home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 146.6 KB | 5,192 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UPrinting.cp
- // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- // Segmentation strategy:
- //
- // PrintRes Resident
- // PrintMain Resident and used at initialization
- // PrintActual Used only during Actual Printing (imaging/spooling)
- // PrintImage Used during imaging only
- // PrintSpool Used only during printing of a Spool File
- // PrintDebug Debugging code
- // PrintFinder Code only ever accessed from Finder Printing
- // PrintInit One-time Initialization Code
- // PrintOpen Code accessed when opening new document
- // PrintNonRes General non-resident code
- // PrintDoCommand Code for Page Setup command
-
- #ifndef __UPRINTING__
- #include "UPrinting.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UCOREERRORMGR__
- #include "UCoreErrorMgr.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILESTREAM__
- #include "UFileStream.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #if qGXPrinting
- # ifndef __GXENVIRONMENT__
- # include <GXEnvironment.h>
- # endif
-
- # ifndef __GXGRAPHICS__
- # include <GXGraphics.h>
- # endif
-
- # ifndef __GXPRINTING__
- # include <GXPrinting.h>
- # endif
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #if !qGXViews
- # ifndef __PRINTING__
- # include <Printing.h>
- # endif
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- // Handy macros for Fixed point manipulation
- #ifndef __GXMATH__
- # ifndef FixedToInt
- # define FixedToInt(a) ((short)((Fixed)(a) + fixed1/2 >> 16))
- # endif
-
- # ifndef IntToFixed
- # define IntToFixed(a) ((Fixed)(a) << 16)
- # endif
- #endif
-
-
- //========================================================================================
- // constants
- //========================================================================================
- enum {
- kClassicQDResolution = 72
- };
-
- //========================================================================================
- // GLOBAL Variables
- //========================================================================================
-
- PenState gBreaksPenState = { {0, 0}, {2, 2}, {patCopy}, {0xCC, 0x66, 0x33, 0x99, 0xCC, 0x66, 0x33, 0x99}};
- Boolean gCancelAllPrinting;
- VRect gStdPageMargins(1 * kClassicQDResolution, 1 * kClassicQDResolution, - 1 * kClassicQDResolution, - 1 * kClassicQDResolution);// 1" margins std default;
- TPrintInfo* gFinderPrintInfo;
- TStdPrintHandler* gJobPrintHandler;
-
- static PrIdleUPP pPrintIdleProc; // For MacPrint
- TPrintInfo* gDefaultPrintInfo;
- FSSpec gTargetPrinter;
-
- #if qGXPrinting
- static GXPrintingEventUPP pGXPrintingEventUPP; // For GX
- static gxShapeSpoolUPP pgxShapeSpoolUPP; // For GX
- static gxPrintingFlattenUPP pgxPrintingFlattenUPP; // For GX
- static gxPrintingFlattenUPP pgxPrintingUnflattenUPP; // For GX
- static gxPrintingFlattenUPP pgxGetSizeHelperUPP; // For GX
- Boolean gUsingGXPrinting;
- #endif
-
- #if !qGXViews
- short TMacPrintJob::fPrintShopOpens;
- TPPrPort TMacPrintJob::fQDPort;
- CStr255 TMacPrintJob::fgLastPrinterName;
- unsigned long TMacPrintJob::fgPrinterChangeLevel;
- #endif
-
- const short kFirstGXFormatIndex = 2;
- const short kFirstMacPrintFormatIndex = 1;
- const ResType kPrintResType[kFirstGXFormatIndex + 1] = { kAlternatePrintInfoRsrcType, kPrintInfoRsrcType, kGXPrintInfoRsrcType };
- const ResNumber kPrintResNumber[kFirstGXFormatIndex + 1] = { kAlternatePrintInfoRsrcID, kPrintInfoRsrcID, kGXPrintInfoRsrcID };
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
-
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintInit
-
- void InitUPrinting()
- {
- if (!gUPrintingInitialized)
- {
- gUPrintingInitialized = TRUE;
-
- TPrintHandler::gCouldPrint = TRUE;
-
- #if qGXPrinting
- if (TView::gGXGraphicsClient && HasQDGXPrinting())
- gUsingGXPrinting = ::GXInitPrinting() == noErr;
-
- if (gUsingGXPrinting)
- {
- TGXJob * aGXPrint = new TGXJob;
- aGXPrint->IGXJob();
- gDefaultPrintInfo = aGXPrint;
-
- }
- else
- #endif
- {
- TMacPrintJob * aMacPrint = new TMacPrintJob;
- aMacPrint->IMacPrintJob();
- gDefaultPrintInfo = aMacPrint;
- }
-
- if (TPrintHandler::gPrintHandler == TPrintHandler::gNullPrintHandler)
- {
- // Install a StdPrintHandler in global variable gPrintHandler
- TStdPrintHandler * aStdPrintHandler = new TStdPrintHandler;
- aStdPrintHandler->IStdPrintHandler();
- aStdPrintHandler->fFinderJobDialog = TRUE;
-
- TPrintHandler::gPrintHandler = aStdPrintHandler;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // NewTPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- TPrintInfo* NewTPrintInfo(Boolean isValid)
- {
- TPrintInfo * returnVal = NULL;
-
- #if qGXPrinting
- if (gUsingGXPrinting)
- {
- TGXJob * gxPrintInfo = new TGXJob;
- gxPrintInfo->IGXJob(NULL, isValid);
- returnVal = gxPrintInfo;
- }
- else
- #endif
- {
- TMacPrintJob * macPrintInfo = new TMacPrintJob;
- macPrintInfo->IMacPrintJob(NULL, isValid);
- returnVal = macPrintInfo;
- }
-
- return returnVal;
- }
-
- //========================================================================================
- // CLASS TPrintInfo
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TPrintInfo,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TPrintInfo::TPrintInfo() :
- fIsValid(FALSE),
- fNeedsDefault(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo destructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintClose
-
- TPrintInfo::~TPrintInfo()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::IPrintInfo
- //----------------------------------------------------------------------------------------
- #pragma segment PrintClose
-
- void TPrintInfo::IPrintInfo()
- {
- IObject();
-
- if (gDefaultPrintInfo && gDefaultPrintInfo != this)
- gDefaultPrintInfo->AddDependent(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TPrintInfo::ReadFrom(TStream* aStream)
- {
- Inherited::ReadFrom(aStream);
-
- fNeedsDefault = FALSE;
-
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetFrom
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetFrom(TPrintInfo* jobToCopy)
- {
- fIsValid = jobToCopy->IsValid();
- fNeedsDefault = jobToCopy->NeedsDefault();
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TPrintInfo::GetSize(Boolean /* asResource */)
- {
- long returnVal = 0;
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- TObject* TPrintInfo::Clone()
- {
- MAVolatileInit(TPrintInfo * , aClonedPrintInfo, (TPrintInfo *)(Inherited::Clone()));
-
- if (gDefaultPrintInfo)
- gDefaultPrintInfo->AddDependent(aClonedPrintInfo);
-
- return aClonedPrintInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)// Override
- {
- switch (theChange)
- {
- case mPrinterChanged:
- Invalidate();
- break;
-
- case mPrinterOpened:
- Update(); // Pool's open!
- break;
-
- default:
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetPaperRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TPrintInfo::GetPaperRect()
- {
- return gZeroVRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetInkRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TPrintInfo::GetInkRect()
- {
- return gZeroVRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetDeviceRes:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CPoint TPrintInfo::GetDeviceRes()
- {
- return CPoint(kClassicQDResolution, kClassicQDResolution);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::Invalidate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::Invalidate()
- {
- fIsValid = FALSE;
- Changed(mPrintInfoChanged, this);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetToDefault()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::IsSetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TPrintInfo::IsSetToDefault()
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage)
- {
- fromPage = toPage = minFromPage = maxToPage = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetPrintPages(long /* fromPage */,
- long /* toPage */,
- long /* minFromPage */,
- long /* maxToPage */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetNumCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TPrintInfo::GetPrintCopies()
- {
- return 1;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetNumCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetPrintCopies(long /* numCopies */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetTargetPrinter:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetTargetPrinter(const FSSpec& /* targetPrinter */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetSpoolFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetSpoolFile(FSSpec& /* spoolFile */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::IsSpooling:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TPrintInfo::IsSpooling()
- {
- return TRUE; // default is spooled printing (normal for the Macintosh)
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::IsMatch
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TPrintInfo::IsMatch(TPrintInfo* /* thePrintInfo */)
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::Update()
- {
- if (!fIsValid && TPrintHandler::gCouldPrint)
- {
- FailInfo fi;
- Try(fi)
- {
- Boolean wantedDefault = fNeedsDefault;
- fNeedsDefault = FALSE;
- TPrintInfo * defaultPrintInfo = GetDefaultPrintInfo();
- if (wantedDefault && IsSetToDefault())
- fIsValid = TRUE; // matches the default. No validation necessary!
- else if (wantedDefault && (defaultPrintInfo != this) && defaultPrintInfo->IsValid())
- SetFrom(defaultPrintInfo);
- else // need to go ask Printing Management
- {
- if (wantedDefault)
- CallPrintDefault();
- else
- CallPrValidate();
-
- fIsValid = TRUE;
- }
-
- fi.Success();
- }
- else // recover
- {
- if (fi.error != errNoPrintDrvr)
- fi.ReSignal();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::Open:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::Open(TObject* /* byWhom */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::IsOpen:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TPrintInfo::IsOpen()
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::Close(TObject* /* byWhom */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- OSErr TPrintInfo::GetError()
- {
- return noErr;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::SetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::SetError(OSErr /* err */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::ClearError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::ClearError()
- {
- SetError(noErr);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::ChkPrintErr:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TPrintInfo::ChkPrintErr(OSErr& err,
- Boolean& ranOutOfSpace)
- {
- Boolean returnVal = TRUE; // proceed
- err = GetError();
- if (err != noErr)
- {
- #if qDebugMsg
- if (gDebugPrinting)
- fprintf(stderr, "Error from PrError is %d\n", err);
- #endif
-
- returnVal = FALSE;
- if (err == iPrSavPFil || err == dskFulErr)
- ranOutOfSpace = TRUE;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::StartJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::StartJob(const CStr255& /* docTitle */ ,
- long /* numPages */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetJobPort:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- GrafPtr TPrintInfo::GetJobPort()
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::FinishJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::FinishJob()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::StartPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::StartPage(long /* pageNumber */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::FinishPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::FinishPage()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::CallJobDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TPrintInfo::CallJobDialog()
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::CallStyleDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TPrintInfo::CallStyleDialog()
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::CallPrValidate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TPrintInfo::CallPrValidate()
- {
- return FALSE;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::CallPrintDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::CallPrintDefault()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::CallPrPicFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TPrintInfo::CallPrPicFile(OSErr& err)
- {
- err = noErr;
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::GetDefaultPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- TPrintInfo* TPrintInfo::GetDefaultPrintInfo()
- {
- return gDefaultPrintInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::JobMerge:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintInfo::JobMerge(TPrintInfo* /* mergeFrom */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::BanishPrintDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::BanishPrintDialog()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::PosePrintDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TPrintInfo::PosePrintDialog(const CStr255& /* docName */, CommandNumber /* aCommandNumber */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintInfo::ShowDocBeingPrinted:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintFinder
-
- void TPrintInfo::ShowDocBeingPrinted(const CStr255& /* docName */, Boolean/* entering */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetMaxSquareResolution:
- //----------------------------------------------------------------------------------------
- void TPrintInfo::GetMaxSquareResolution(Fixed& hRes, Fixed& vRes)
- {
- hRes = IntToFixed(kClassicQDResolution);
- vRes = IntToFixed(kClassicQDResolution);
-
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetResolution:
- //----------------------------------------------------------------------------------------
- void TPrintInfo::SetResolution(Fixed /* hRes */, Fixed /* vRes */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::MaximizeResolution:
- //----------------------------------------------------------------------------------------
- void TPrintInfo::MaximizeResolution()
- {
- Fixed hRes;
- Fixed vRes;
- GetMaxSquareResolution(hRes, vRes);
- SetResolution(hRes, vRes);
- }
-
- #if qGXPrinting
- //========================================================================================
- // CLASS TGXJob
- //========================================================================================
- #undef Inherited
- #define Inherited TPrintInfo
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TGXJob,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TGXJob constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TGXJob::TGXJob() :
- fgxJob(NULL),
- fPrintViewPort(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob destructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintClose
-
- TGXJob::~TGXJob()
- {
- if (fgxJob)
- {
- ::GXDisposeJob(fgxJob);
- fgxJob = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::IGXPrintInfo
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::IGXJob(gxJob itsgxJob,
- Boolean isValid)
- {
- IPrintInfo();
-
- if (itsgxJob)
- {
- fgxJob = itsgxJob;
- AdoptJob(fgxJob);
- fIsValid = isValid;
- }
- else
- {
- FailOSErr(::GXNewJob(&fgxJob));
- AdoptJob(fgxJob);
- SetToDefault();
- }
-
- if (!pgxShapeSpoolUPP)
- FailNIL(pgxShapeSpoolUPP = NewgxShapeSpoolProc(MyPrintAShape));
-
- if (!pGXPrintingEventUPP)
- FailNIL(pGXPrintingEventUPP = NewGXPrintingEventProc(PrintingEventOverride));
-
- if (!pgxPrintingFlattenUPP)
- FailNIL(pgxPrintingFlattenUPP = NewgxPrintingFlattenProc(MyFlattenFunction));
-
- if (!pgxPrintingUnflattenUPP)
- FailNIL(pgxPrintingUnflattenUPP = NewgxPrintingFlattenProc(MyUnflattenFunction));
-
- if (!pgxGetSizeHelperUPP)
- FailNIL(pgxGetSizeHelperUPP = NewgxPrintingFlattenProc(GetSizeHelper));
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TGXJob::ReadFrom(TStream* aStream)
- {
- Inherited::ReadFrom(aStream);
-
- if (!fgxJob)
- {
- FailOSErr(::GXNewJob(&fgxJob));
- AdoptJob(fgxJob);
- }
-
- ::GXUnflattenJob(fgxJob, (gxPrintingFlattenProc)pgxPrintingUnflattenUPP, aStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::ConvertFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TGXJob::ConvertFrom(TStream* aStream)
- {
- Inherited::ReadFrom(aStream);
-
- THPrint aPrint = (THPrint)NewPermHandleClear(sizeof(TPrint));
-
- SignedByte savedState = LockHandleHigh((Handle)aPrint);
- aStream->ReadBytes(*aPrint, sizeof(TPrint));
- ::HSetState((Handle)aPrint, savedState);
-
-
- if (!fgxJob)
- {
- FailOSErr(::GXNewJob(&fgxJob));
- AdoptJob(fgxJob);
- }
-
- ::GXConvertPrintRecord(fgxJob, aPrint);
-
- DisposeIfHandle((Handle)aPrint);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TGXJob::WriteTo(TStream* aStream)
- {
- Inherited::WriteTo(aStream);
-
- if (fgxJob)
- {
- ::GXFlattenJob(fgxJob, (gxPrintingFlattenProc)pgxPrintingFlattenUPP, aStream);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetFrom
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetFrom(TPrintInfo* jobToCopy)
- {
- Inherited::SetFrom(jobToCopy);
-
- TGXJob * gxToCopy = (TGXJob *)jobToCopy;
-
- ::GXCopyJob(gxToCopy->GetRawgxJob(), GetRawgxJob());
-
- if (fIsValid)
- Changed(mPrintInfoChanged, this);
- else
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetFrom
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetFrom(gxJob jobToCopy, Boolean isValid,
- Boolean needsDefault)
- {
- ::GXCopyJob(jobToCopy, fgxJob);
-
- fIsValid = isValid;
- fNeedsDefault = needsDefault;
-
- if (fIsValid)
- Changed(mPrintInfoChanged, this);
- else
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TGXJob::GetSize(Boolean /* asResource */)
- {
- long returnVal = 0;
-
- // the helper function will total up the bytes
- if (GetRawgxJob())
- ::GXFlattenJob(GetRawgxJob(), (gxPrintingFlattenProc)pgxGetSizeHelperUPP, &returnVal);
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- pascal OSErr TGXJob::GetSizeHelper(long size,
- void* /* data */,
- void* refCon)
- {
- *(long*)refCon += size;
-
- return noErr;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TGXJob::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- TObject* TGXJob::Clone()
- {
- MAVolatileInit(TGXJob * , aClonedPrintInfo, (TGXJob *)(Inherited::Clone()));
-
- if (GetRawgxJob())
- {
- aClonedPrintInfo->fgxJob = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- //SRF fix error handling
- gxJob aClonedgxJob = ::GXCopyJob(fgxJob, NULL);
- aClonedPrintInfo->fgxJob = aClonedgxJob;
-
- fi.Success();
- }
- else
- {
- aClonedPrintInfo->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedPrintInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetPaperRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TGXJob::GetPaperRect()
- {
- gxFormat theFormat = ::GXGetJobFormat(GetgxJob(), 1); //••• Get the default format for now.
-
- gxRectangle pageSize;
- gxRectangle paperSize;
- ::GXGetFormatDimensions( theFormat, &pageSize, &paperSize);
-
- VRect thePaper;
- thePaper.top = FixedTruncate(paperSize.top);
- thePaper.left = FixedTruncate(paperSize.left);
- thePaper.bottom = FixedTruncate(paperSize.bottom);
- thePaper.right = FixedTruncate(paperSize.right);
-
- return thePaper;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetInkRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TGXJob::GetInkRect()
- {
-
- gxFormat theFormat = ::GXGetJobFormat( GetgxJob(), 1); //••• Get the default format for now.
-
- gxRectangle pageSize;
- gxRectangle paperSize;
- ::GXGetFormatDimensions( theFormat, &pageSize, &paperSize);
-
- VRect ink;
- ink.top = FixedTruncate(pageSize.top);
- ink.left = FixedTruncate(pageSize.left);
- ink.bottom = FixedTruncate(pageSize.bottom);
- ink.right = FixedTruncate(pageSize.right);
-
- return ink;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetDeviceRes:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CPoint TGXJob::GetDeviceRes()
- {
- // Get the formatting printer
- gxPrinter formatPrinter = ::GXGetJobFormattingPrinter(GetgxJob());
-
- // Get the current view device and its mapping
- gxViewDevice printerVDev = ::GXGetPrinterViewDevice(formatPrinter, 0);
- gxMapping vDevMapping;
- ::GXGetViewDeviceMapping(printerVDev, &vDevMapping);
-
- long hRes = vDevMapping.map[0][0];
- long vRes = vDevMapping.map[1][1];
-
- // Convert scaling factors (multiples of kClassicQDResolution (72) dpi) into
- // resolutions.
-
- hRes = FixedToInt(FixedMultiply(hRes, IntToFixed(kClassicQDResolution)));
- vRes = FixedToInt(FixedMultiply(vRes, IntToFixed(kClassicQDResolution)));
-
- return CPoint((short) hRes, (short) vRes);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage)
- {
- // Get the job collection
- Collection jobCollection = GXGetJobCollection(GetgxJob());
-
- long oldDataSize;
- long index;
- FailOSErr(GetCollectionItemInfo(jobCollection,
- gxPageRangeTag,
- gxPrintingTagID,
- &index,
- &oldDataSize,
- dontWantAttributes));
-
- gxPageRangeInfo pageRangeInfo;
- FailOSErr(GetCollectionItem(jobCollection,
- gxPageRangeTag,
- gxPrintingTagID,
- &oldDataSize,
- &pageRangeInfo));
-
-
- fromPage = pageRangeInfo.simpleRange.fromPage;
- toPage = pageRangeInfo.simpleRange.toPage;
-
- minFromPage = pageRangeInfo.minFromPage;
- maxToPage = pageRangeInfo.maxToPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetPrintPages(long fromPage,
- long toPage,
- long minFromPage,
- long maxToPage)
- {
- // Get the job collection
- Collection jobCollection = GXGetJobCollection(GetgxJob());
-
- long oldDataSize;
- long index;
- FailOSErr(GetCollectionItemInfo(jobCollection,
- gxPageRangeTag,
- gxPrintingTagID,
- &index,
- &oldDataSize,
- dontWantAttributes));
-
- gxPageRangeInfo pageRangeInfo;
- FailOSErr(GetCollectionItem(jobCollection,
- gxPageRangeTag,
- gxPrintingTagID,
- &oldDataSize,
- &pageRangeInfo));
-
- pageRangeInfo.minFromPage = minFromPage;
- pageRangeInfo.maxToPage = maxToPage;
-
- pageRangeInfo.simpleRange.fromPage = fromPage;
- pageRangeInfo.simpleRange.toPage = toPage;
-
- // pageRangeInfo.simpleRange.optionChosen = gxDefaultPageRange;
- pageRangeInfo.simpleRange.printAll = (fromPage == minFromPage) && (toPage == maxToPage);
-
- FailOSErr(ReplaceIndexedCollectionItem(jobCollection,
- index,
- oldDataSize,
- &pageRangeInfo));
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetPrintCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TGXJob::GetPrintCopies()
- {
- // Get the job collection
- Collection jobCollection = GXGetJobCollection(GetgxJob());
-
- long oldDataSize;
- FailOSErr(GetCollectionItemInfo(jobCollection,
- gxCopiesTag,
- gxPrintingTagID,
- dontWantIndex,
- &oldDataSize,
- dontWantAttributes));
-
- gxCopiesInfo copiesInfo;
- FailOSErr(GetCollectionItem(jobCollection,
- gxCopiesTag,
- gxPrintingTagID,
- &oldDataSize,
- &copiesInfo));
-
- return copiesInfo.copies;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetPrintCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetPrintCopies(long numCopies)
- {
- // Get the job collection
- Collection jobCollection = GXGetJobCollection(GetgxJob());
-
- long oldDataSize;
- long index;
- FailOSErr(GetCollectionItemInfo(jobCollection,
- gxCopiesTag,
- gxPrintingTagID,
- &index,
- &oldDataSize,
- dontWantAttributes));
-
- gxCopiesInfo copiesInfo;
- FailOSErr(GetCollectionItem(jobCollection,
- gxCopiesTag,
- gxPrintingTagID,
- &oldDataSize,
- &copiesInfo));
-
-
- copiesInfo.copies = numCopies;
- FailOSErr(ReplaceIndexedCollectionItem(jobCollection,
- index,
- oldDataSize,
- &copiesInfo));
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetTargetPrinter:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetTargetPrinter(const FSSpec& targetPrinter)
- {
- ::GXSelectJobOutputPrinter(GetgxJob(), CStr31(targetPrinter.name));
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetToDefault()
- {
- fNeedsDefault = TRUE;
-
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::IsSetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TGXJob::IsSetToDefault()
- {
- // we don't really know how to compare the job to see if it's just like the default
- // so let's just assume that if we even have a job it's not default
- return fgxJob ? FALSE : TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::AdoptJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::AdoptJob(gxJob itsgxJob)
- {
- ::GXInstallApplicationOverride(itsgxJob, gxPrintingEventMsg, pGXPrintingEventUPP);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::PrintingEventOverride:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- OSErr TGXJob::PrintingEventOverride(EventRecord* anEvent,
- Boolean filterEvent)
- {
- if (!filterEvent && gDispatcher)
- {
- static TToolboxEvent* bufferableEvent;
-
- Boolean needsSecondaryEvent = FALSE;
- if (!bufferableEvent)
- {
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- bufferableEvent = new TToolboxEvent;
- AllocateObjectsFromPerm(oldObjectPerm);
- needsSecondaryEvent = bufferableEvent->IToolboxEvent(gDispatcher, *anEvent);
- }
- else
- bufferableEvent->AddSecondaryKeyEvent(*anEvent);
-
- if (!needsSecondaryEvent)
- {
- ++gDispatcher->fEventLevel;
- gDispatcher->fSysWindowActive = TRUE;
-
-
- InvalidateMenus();
- gDispatcher->InvalidateFocus();
- bufferableEvent->Process();
-
-
- gDispatcher->fSysWindowActive = FALSE;
- --gDispatcher->fEventLevel;
- bufferableEvent = NULL;
- }
- }
-
- return noErr;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetgxJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- gxJob TGXJob::GetgxJob()
- {
- Update();
-
- return fgxJob;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetRawgxJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- gxJob TGXJob::GetRawgxJob()
- {
- return fgxJob;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- OSErr TGXJob::GetError()
- {
- return ::GXGetJobError(GetgxJob());
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::SetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::SetError(OSErr err)
- {
- ::GXSetJobError(GetRawgxJob(), err);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::StartJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TGXJob::StartJob(const CStr255& docTitle,
- long numPages)
- {
- ::GXStartJob(GetgxJob(), CStr255(docTitle), numPages);
-
- FailOSErr(GetError());
-
- fPrintViewPort = ::GXNewViewPort(gxScreenViewDevices);
- //•••SRF How do I test this for error?
-
- OpenCPort(&fQDPortRec);
- fQDPort = &fQDPortRec;
-
- SetPort(GetJobPort());
-
- CRect wideopenRect(-32766, -32766, 32767, 32767);
- RectRgn(GetJobPort()->visRgn, &wideopenRect);
- ClipRect(&wideopenRect);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetJobPort:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- GrafPtr TGXJob::GetJobPort()
- {
- return (GrafPtr)fQDPort;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::FinishJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TGXJob::FinishJob()
- {
- ::GXFinishJob(GetgxJob());
- OSErr err = GetError();
-
- ::GXDisposeViewPort(fPrintViewPort);
- fPrintViewPort = NULL;
-
- SetPortWindowPort(gWorkPort);
-
- CloseCPort(&fQDPortRec);
- fQDPort = NULL; // So we don't accidentally use it
-
- FailOSErr(err);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::StartPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TGXJob::StartPage(long pageNumber)
- {
- //••• Here is where we would call back thru the TPrintHandler to the view
- // to get the specific pages format
-
- gxFormat pageFormat = ::GXGetJobFormat(GetgxJob(), 1);
-
- ::GXStartPage(GetgxJob(), pageNumber, pageFormat, 1, &fPrintViewPort);
- FailOSErr(GetError());
-
- fSpoolData.printViewPort = fPrintViewPort;
-
- // Install Translators
- ::GXGetFormatDimensions(pageFormat, &fSpoolData.pageArea, NULL);
-
- CRect everywhereRect(0, 0, 32767, 32767);
-
- ::GXInstallQDTranslator(GetJobPort(),
- gxDefaultOptionsTranslation,
- &everywhereRect, &everywhereRect,
- CPoint(1, 1) /* patStretch */,
- pgxShapeSpoolUPP,
- &fSpoolData);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::FinishPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TGXJob::FinishPage()
- {
- // Remove Translators
- ::GXRemoveQDTranslator(GetJobPort(), NULL);
-
- // Finish the page.
-
- ::GXFinishPage(GetgxJob());
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::CallJobDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TGXJob::CallJobDialog()
- {
- FailOSErr(MAInteractWithUser());
- PullApplicationToFront();
-
- SetCursor(&qd.arrow);
- if (gDispatcher)
- gDispatcher->InvalidateMouseRegions();
-
- gDispatcher->AboutToLoseControl(TRUE); // so scrap gets converted and floaters get removed
-
- gxEditMenuRecord editMenuRecord;
- editMenuRecord.editMenuID = mEdit;
- short itsMenu;
-
- CommandToMenuItem(cCut, itsMenu, editMenuRecord.cutItem);
- CommandToMenuItem(cCopy, itsMenu, editMenuRecord.copyItem);
- CommandToMenuItem(cPaste, itsMenu, editMenuRecord.pasteItem);
- CommandToMenuItem(cClear, itsMenu, editMenuRecord.clearItem);
- CommandToMenuItem(cUndo, itsMenu, editMenuRecord.undoItem);
- EnableItem(MAGetMenu(mEdit), 0); // ensure the menu is enabled for GX
-
- //SRF - force the even handler in place
- AdoptJob(GetgxJob());
-
- gxDialogResult aGXDialogResult = ::GXJobPrintDialog(GetgxJob(), &editMenuRecord);
- Boolean result = aGXDialogResult == gxOKSelected;
-
- gDispatcher->RegainControl(TRUE); // scrap gets converted, printer gets checked, floaters get restored
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::CallStyleDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TGXJob::CallStyleDialog()
- {
- FailOSErr(MAInteractWithUser());
- PullApplicationToFront();
-
- SetCursor(&qd.arrow);
- if (gDispatcher)
- gDispatcher->InvalidateMouseRegions();
-
- gDispatcher->AboutToLoseControl(TRUE); // so scrap gets converted and floaters get removed
-
- gxEditMenuRecord editMenuRecord;
- editMenuRecord.editMenuID = mEdit;
- short itsMenu;
-
- CommandToMenuItem(cCut, itsMenu, editMenuRecord.cutItem);
- CommandToMenuItem(cCopy, itsMenu, editMenuRecord.copyItem);
- CommandToMenuItem(cPaste, itsMenu, editMenuRecord.pasteItem);
- CommandToMenuItem(cClear, itsMenu, editMenuRecord.clearItem);
- CommandToMenuItem(cUndo, itsMenu, editMenuRecord.undoItem);
- EnableItem(MAGetMenu(mEdit), 0); // ensure the menu is enabled for GX
-
- //SRF - force the event handler in place
- AdoptJob(GetgxJob());
-
- gxDialogResult aGXDialogResult = ::GXJobDefaultFormatDialog(GetgxJob(), &editMenuRecord);
- Boolean result = aGXDialogResult == gxOKSelected;
-
- gDispatcher->RegainControl(TRUE); // scrap gets converted, printer gets checked, floaters get restored
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::CallPrValidate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TGXJob::CallPrValidate()
- {
- static const Boolean kNoChange = FALSE;
-
- return kNoChange;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TGXJob::CallPrintDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TGXJob::CallPrintDefault()
- {
- if (fgxJob)
- {
- ::GXDisposeJob(fgxJob);
- fgxJob = NULL;
- }
-
- FailOSErr(::GXNewJob(&fgxJob));
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::Update()
- {
- Inherited::Update();
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)// Override
- {
- switch (theChange)
- {
- case mRegainControl:
- TPrintHandler::gCouldPrint = TRUE; // Could be OK now
- InvalidateMenus(); // so the menus stay in sync.
-
- Invalidate();
- Changed(mPrinterChanged, this);
- break;
-
- default:
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::JobMerge:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TGXJob::JobMerge(TPrintInfo* /* mergeFrom */)
- {
- //SRF fix this
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::MyPrintAShape:
- //----------------------------------------------------------------------------------------
- OSErr TGXJob::MyPrintAShape(gxShape currentShape, long refCon)
- {
- // Don't waste time spooling the shape if it's being
- // drawn completely off the page.
-
- MySpoolDataRec* spoolData = (MySpoolDataRec*) refCon;
- gxShapeType theShapeType = ::GXGetShapeType(currentShape);
-
- #if 0
- // Actually, MacApp has already gone to great lengths to ensure that we only printed
- // Stuff that intersects the page. This test is unnecessary, and in fact, since we are
- // not updating the spoolData.pageArea... it doesn't work!
- if ((theShapeType == gxEmptyType) ||
- (theShapeType == gxFullType) ||
- (theShapeType == gxPictureType) ||
- (GXTouchesBoundsShape(&spoolData->pageArea, currentShape)))
- #endif
- {
- ::GXSetShapeViewPorts(currentShape, 1, &spoolData->printViewPort);
- ::GXDrawShape(currentShape);
- }
-
- return (OSErr) ::GXGetGraphicsError(NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::MyUnflattenFunction:
- //----------------------------------------------------------------------------------------
- pascal OSErr TGXJob::MyFlattenFunction (long size, void *data, void *refCon)
- {
- MAVolatileInit(OSErr, returnVal, noErr);
-
- FailInfo fi;
- Try(fi)
- {
- ((TStream*)refCon)->WriteBytes(data, size);
-
- fi.Success();
- }
- else // recover
- {
- returnVal = fi.error;
- // drop thru
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::MyUnflattenFunction:
- //----------------------------------------------------------------------------------------
- pascal OSErr TGXJob::MyUnflattenFunction (long size, void *data, void *refCon)
- {
- MAVolatileInit(OSErr, returnVal, noErr);
-
- FailInfo fi;
- Try(fi)
- {
- ((TStream*)refCon)->ReadBytes(data, size);
-
- fi.Success();
- }
- else // recover
- {
- returnVal = fi.error;
- // drop thru
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TGXJob::GetMaxSquareResolution:
- //----------------------------------------------------------------------------------------
- void TGXJob::GetMaxSquareResolution(Fixed& hRes, Fixed& vRes)
- {
- hRes = 0;
- vRes = 0;
-
- // Get the formatting printer and the number of
- // view devices for that printer.
-
- gxPrinter formatPrinter = ::GXGetJobFormattingPrinter(GetgxJob());
- long numViewDevices = ::GXCountPrinterViewDevices (formatPrinter);
-
- // Loop through the view devices that this printer supports.
- for (long idx = 1; idx <= numViewDevices; idx++)
- {
- gxViewDevice printerVDev = ::GXGetPrinterViewDevice(formatPrinter, idx);
- gxMapping vDevMapping;
- ::GXGetViewDeviceMapping(printerVDev, &vDevMapping);
-
- if ((vDevMapping.map[0][0] > hRes) && (vDevMapping.map[1][1] > vRes))
- {
- hRes = vDevMapping.map[0][0];
- vRes = vDevMapping.map[1][1];
- }
- }
-
-
- // Convert scaling factors (multiples of kClassicQDResolution (72) dpi) into
- // resolutions.
-
- hRes = FixedMultiply(hRes, IntToFixed(kClassicQDResolution));
- vRes = FixedMultiply(vRes, IntToFixed(kClassicQDResolution));
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetResolution:
- //----------------------------------------------------------------------------------------
- void TGXJob::SetResolution(Fixed hRes, Fixed vRes)
- {
- // Convert scaling factors (multiples of kClassicQDResolution (72) dpi) into
- // resolutions.
-
- hRes = FixedDivide(hRes, IntToFixed(kClassicQDResolution));
- vRes = FixedDivide(vRes, IntToFixed(kClassicQDResolution));
-
-
- // Get the formatting printer and the number of
- // view devices for that printer.
-
- gxPrinter formatPrinter = ::GXGetJobFormattingPrinter(GetgxJob());
- long numViewDevices = ::GXCountPrinterViewDevices (formatPrinter);
-
- // Loop through the view devices that this printer supports.
- for (long idx = 1; idx <= numViewDevices; idx++)
- {
- gxViewDevice printerVDev = ::GXGetPrinterViewDevice(formatPrinter, idx);
- gxMapping vDevMapping;
- ::GXGetViewDeviceMapping(printerVDev, &vDevMapping);
-
- if ((vDevMapping.map[0][0] == hRes) && (vDevMapping.map[1][1] == vRes))
- {
- ::GXSelectPrinterViewDevice(formatPrinter, idx);
- }
- }
-
-
- Invalidate();
- }
-
- #endif
-
- //========================================================================================
- // CLASS CInMacPrint
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::new:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void* CInMacPrint::operator new(size_t /*size*/)
- {
- return NULL; // don't allow heap-based allocation
- }
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::delete:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void CInMacPrint::operator delete(void*)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::CInMacPrint:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CInMacPrint::CInMacPrint(TPrintInfo* itsPrintinfo, TObject* byWhom, Boolean active)
- {
- fIsActive = active;
- fPrintShopOpened = false;
-
- if (fIsActive)
- {
- #if qDebug
- # if qGXPrinting
- if (gUsingGXPrinting)
- ::DebugStr("\pYikes!!, making an active CInMacPrint call while using QD GX!");
- # endif
- #endif
-
- // Setup the FailInfo to catch any failures while this object is in scope
- fFailInfo.SetCleanupProc(CInMacPrint::CallCleanup, this);
-
- fPrintInfo = itsPrintinfo ? itsPrintinfo : gDefaultPrintInfo;
- fByWhom = byWhom ? byWhom : fPrintInfo;
-
-
- fResFile = MACurResFile();
- fPrintInfo->ClearError(); // Clear printer-error flag
-
- fPrintInfo->Open(fByWhom);
- fPrintShopOpened = true;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::~CInMacPrint:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CInMacPrint::~CInMacPrint()
- {
- if (fIsActive)
- {
- Cleanup();
-
- fFailInfo.Success();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::Cleanup:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void CInMacPrint::Cleanup()
- {
- if (fPrintShopOpened)
- {
- fPrintInfo->Close(fByWhom);
- MAUseResFile(fResFile);
- SetPortWindowPort(gWorkPort); // Might be left looking at a dead port
- gDispatcher->InvalidateFocus();
-
- fPrintShopOpened = false;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CInMacPrint::CallCleanup:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- /*static*/
- void CInMacPrint::CallCleanup(void* context)
- {
- if (((CInMacPrint *)context)->fFailInfo.error == errNoPrintDrvr)
- {
- TPrintHandler::gCouldPrint = FALSE; // well, we didn't make it. don't bother to try again
- InvalidateMenus(); // so the menus stay in sync/
- }
-
- ((CInMacPrint *)context)->Cleanup();
- }
-
- //========================================================================================
- // CLASS TMacPrintJob
- //========================================================================================
- #undef Inherited
- #define Inherited TPrintInfo
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TMacPrintJob,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TMacPrintJob::TMacPrintJob() :
- fHPrint(NULL),
- fPrintDialog(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob destructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintClose
-
- TMacPrintJob::~TMacPrintJob()
- {
- fHPrint = (THPrint)DisposeIfHandle((Handle)fHPrint);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IMacPrintInfo
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::IMacPrintJob(THPrint itsHPrint,
- Boolean isValid)
- {
- IPrintInfo();
-
- if (itsHPrint)
- {
- fHPrint = itsHPrint;
- fIsValid = isValid;
- }
- else
- {
- fHPrint = (THPrint)NewPermHandleClear(sizeof(TPrint));
- SetToDefault();
- }
-
- if (!fgPrinterChangeLevel)
- CheckPrinterChangeLevel();
- fPrinterChangeLevel = fgPrinterChangeLevel;
-
- if (!pPrintIdleProc)
- FailNIL(pPrintIdleProc = NewPrIdleProc(TMacPrintJob::IdleProc));
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TMacPrintJob::ReadFrom(TStream* aStream)
- {
- Inherited::ReadFrom(aStream);
-
- if (!fHPrint)
- fHPrint = (THPrint)NewPermHandleClear(sizeof(TPrint));
-
- SignedByte savedState = LockHandleHigh((Handle)fHPrint);
- aStream->ReadBytes(*fHPrint, GetSize());
- HSetState((Handle)fHPrint, savedState);
-
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TMacPrintJob::WriteTo(TStream* aStream)
- {
- Inherited::WriteTo(aStream);
-
- if (fHPrint)
- {
- // Don't need to validate it before saving it b/c it will be
- // validated before USE when loaded again in the future.
- // Also, if a document is opened, modified and saved without modifying
- // the printinfo (via page setup or printing or something; then the printshop
- // never even needs to be opened at all (Saving lots & lots of time)
-
- SignedByte savedState = LockHandleHigh((Handle)fHPrint);
- aStream->WriteBytes(*fHPrint, GetSize());
- HSetState((Handle)fHPrint, savedState);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetFrom
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetFrom(TPrintInfo* jobToCopy)
- {
- Inherited::SetFrom(jobToCopy);
-
- TMacPrintJob * macPrintToCopy = (TMacPrintJob *)jobToCopy;
-
- MABlockMove(*macPrintToCopy->GetRawHPrint(), *GetRawHPrint(), GetHandleSize((Handle)GetRawHPrint()));
-
- if (fIsValid)
- Changed(mPrintInfoChanged, this);
- else
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetFrom
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetFrom(THPrint hPrintToCopy,
- Boolean isValid,
- Boolean needsDefault)
- {
- MABlockMove(*hPrintToCopy, *fHPrint, GetHandleSize((Handle)hPrintToCopy));
-
- fIsValid = isValid;
- fNeedsDefault = needsDefault;
-
- if (fIsValid)
- Changed(mPrintInfoChanged, this);
- else
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TMacPrintJob::GetSize(Boolean /* asResource */)
- {
- long returnVal = 0;
- if (fHPrint)
- returnVal = GetHandleSize((Handle)fHPrint);
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IsMatch
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TMacPrintJob::IsMatch(TPrintInfo* thePrintInfo)
- {
- return (fIsValid && EqualBlocks((Ptr) * GetRawHPrint(), (Ptr) * ((TMacPrintJob *)thePrintInfo)->GetRawHPrint(), thePrintInfo->GetSize()));
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetToDefault()
- {
- fNeedsDefault = TRUE;
-
- // Print Manager code could unavailable, but we would want some plausible things
- // anyway - set up for Portrait Tall Adj.
- TPrint & anHPrint = **fHPrint;
- anHPrint.iPrVersion = 0; // something invalid
-
- anHPrint.prInfo.iHRes = kClassicQDResolution;
- anHPrint.prInfo.iVRes = kClassicQDResolution;
- anHPrint.prInfo.rPage = CRect(0, 0, 576, 752);// must have its top left & (0,0)
-
- anHPrint.rPaper = CRect(-18, -36, 594, 756);
- anHPrint.prStl.iPageV = 1320; // 11 inches in 120th of an inch
- anHPrint.prStl.iPageH = 1020; // 8.5 inches in 120th of an inch
-
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IsSetToDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TMacPrintJob::IsSetToDefault()
- {
- return fNeedsDefault || GetDefaultPrintInfo()->IsMatch(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::Clone
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- TObject* TMacPrintJob::Clone()
- {
- MAVolatileInit(TMacPrintJob * , aClonedPrintInfo, (TMacPrintJob *)(Inherited::Clone()));
-
- if (fHPrint)
- {
- aClonedPrintInfo->fHPrint = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- THPrint aClonedHPrint = fHPrint;
- PermHandToHand((Handle &)aClonedHPrint);
- aClonedPrintInfo->fHPrint = aClonedHPrint;
-
- fi.Success();
- }
- else
- {
- aClonedPrintInfo->Free();
- fi.ReSignal();
- }
- }
- aClonedPrintInfo->fPrintDialog = NULL; // Sorry, but this just can't be cloned
-
- return aClonedPrintInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage)
- {
- fromPage = (*GetHPrint())->prJob.iFstPage;
- toPage = (*GetHPrint())->prJob.iLstPage;
-
- minFromPage = fMaxToPage;
- maxToPage = fMaxToPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetPrintPages:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetPrintPages(long fromPage,
- long toPage,
- long minFromPage,
- long maxToPage)
- {
- (*GetHPrint())->prJob.iFstPage = (short)fromPage;
- (*GetHPrint())->prJob.iLstPage = (short)toPage;
-
- fMinFromPage = minFromPage;
- fMaxToPage = maxToPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetNumCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TMacPrintJob::GetPrintCopies()
- {
- return (*GetHPrint())->prJob.iCopies;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetNumCopies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetPrintCopies(long numCopies)
- {
- (*GetHPrint())->prJob.iCopies = numCopies;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetSpoolFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetSpoolFile(FSSpec& spoolFile)
- {
- *((CStr31*)((*GetHPrint())->prJob.pFileName)) = spoolFile.name;
- ((*GetHPrint())->prJob.iFileVol = spoolFile.vRefNum);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IsSpooling:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TMacPrintJob::IsSpooling()
- {
- return ((*GetHPrint())->prJob.bJDocLoop == bSpoolLoop);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetPaperRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TMacPrintJob::GetPaperRect()
- {
- return (*GetHPrint())->rPaper;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetInkRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TMacPrintJob::GetInkRect()
- {
- return (*GetHPrint())->prInfo.rPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetDeviceRes:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CPoint TMacPrintJob::GetDeviceRes()
- {
- return *(CPoint*)&(*GetHPrint())->prInfo.iVRes;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetHPrint:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- THPrint TMacPrintJob::GetHPrint()
- {
- Update();
-
- return fHPrint;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetRawHPrint:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- THPrint TMacPrintJob::GetRawHPrint()
- {
- return fHPrint;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CheckPrinterChangeLevel:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- unsigned long TMacPrintJob::CheckPrinterChangeLevel()
- {
- Boolean returnVal = false;
-
- CStr255 driverName;
- GetDriverName(driverName);
-
- if (!EqualString(driverName, fgLastPrinterName, FALSE, TRUE))
- returnVal = TRUE;
-
- if (returnVal)
- {
- fgLastPrinterName = driverName; // Save it for later
- fgPrinterChangeLevel++; // bump the change level
-
- TPrintHandler::gCouldPrint = TRUE; // Could be OK now
- InvalidateMenus(); // so the menus stay in sync.
- }
-
- return fgPrinterChangeLevel;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::Open:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::Open(TObject* byWhom)
- {
- // The Universal Headers as of 10/17/95 don't provide the following constant!!!
- static const OSErr kPAPNoPrinter = -4101;
-
- Boolean didOpen = FALSE;
-
- if (fPrintShopOpens == 0)
- {
- PrOpen(); // Open the print shop
- OSErr err = GetError(); // Get code
- if (err != noErr)
- {
- if ((err == fnfErr) || (err == resFNotFound) || (err == resNotFound) || (err == dirNFErr) || (err == kPAPNoPrinter))
- err = errNoPrintDrvr;
- else if ((err == fBsyErr) || (err == opWrErr))
- err = errPrintDriverBusy;
- Failure(err, 0);
- }
- didOpen = TRUE;
- }
- ++fPrintShopOpens;
-
- if (didOpen)
- Changed(mPrinterOpened, byWhom);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IsOpen:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TMacPrintJob::IsOpen()
- {
- return fPrintShopOpens > 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::Close(TObject* byWhom)
- {
- Boolean didClose = FALSE;
-
- if (fPrintShopOpens == 1)
- {
- ::PrClose();
- #if qDebugMsg
- OSErr err = GetError();
- // Now check for fresh error from Print Manager --
- // only for debugging, since ChkPrintErr
- // checks afresh in the real world
- if (err != noErr)
- fprintf(stderr, "Error from Print Manager is: %1d\n", err);
- #endif
-
- didClose = TRUE;
- }
-
- --fPrintShopOpens;
-
- if (fPrintShopOpens < 0)
- {
- fPrintShopOpens = 0;
- #if qDebugMsg
- fprintf(stderr, "Too many calls to TMacPrintJob::Close\n");
- #endif
-
- }
-
- if (didClose)
- Changed(mPrinterClosed, byWhom);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- OSErr TMacPrintJob::GetError()
- {
- return ::PrError();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetError:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::SetError(OSErr err)
- {
- ::PrSetError(err);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::StartJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::StartJob(const CStr255& docTitle,
- long /* numPages */)
- {
- CInMacPrint inMacPrint(this);
-
- fCurrentDocTitle = docTitle;
- fQDPort = ::PrOpenDoc(GetHPrint(), NULL, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetJobPort:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- GrafPtr TMacPrintJob::GetJobPort()
- {
- return (GrafPtr)fQDPort;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::FinishJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::FinishJob()
- {
- ::PrCloseDoc((TPPrPort)GetJobPort()); // This will close the port!
- fQDPort = NULL;
- ::SetPortWindowPort(gWorkPort);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::StartPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::StartPage(long /* pageNumber */)
- {
- ::PrOpenPage((TPPrPort)GetJobPort(), NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::FinishPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::FinishPage()
- {
- ::PrClosePage((TPPrPort)GetJobPort());
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CallJobDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TMacPrintJob::CallJobDialog()
- {
- FailOSErr(MAInteractWithUser());
- PullApplicationToFront();
-
- SetCursor(&qd.arrow);
- if (gDispatcher)
- gDispatcher->InvalidateMouseRegions();
-
- CInMacPrint inMacPrint(this);
-
- gDispatcher->AboutToLoseControl(TRUE); // so scrap gets converted and floaters get removed
- Boolean result = ::PrJobDialog(GetHPrint());
- gDispatcher->RegainControl(TRUE); // scrap gets converted, printer gets checked, floaters get restored
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CallStyleDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TMacPrintJob::CallStyleDialog()
- {
- FailOSErr(MAInteractWithUser());
- PullApplicationToFront();
-
- SetCursor(&qd.arrow);
- if (gDispatcher)
- gDispatcher->InvalidateMouseRegions();
-
- CInMacPrint inMacPrint(this);
-
- gDispatcher->AboutToLoseControl(TRUE); // so scrap gets converted and floaters get removed
- Boolean result = ::PrStlDialog(GetHPrint());
- gDispatcher->RegainControl(TRUE); // scrap gets converted, printer gets checked, floaters get restored
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CallPrValidate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TMacPrintJob::CallPrValidate()
- {
- CInMacPrint inMacPrint(this, this);
- Boolean result = ::PrValidate(GetRawHPrint());
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CallPrintDefault:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::CallPrintDefault()
- {
- CInMacPrint inMacPrint(this, this);
-
- PrintDefault(GetRawHPrint());
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::CallPrPicFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TMacPrintJob::CallPrPicFile(OSErr& err)
- {
- CInMacPrint inMacPrint(this, this);
-
- Boolean returnVal = TRUE;
-
- TPrStatus prStatus;
- ::PrPicFile(GetRawHPrint(), NULL, NULL, NULL, &prStatus);
-
- Boolean b;
-
- if (returnVal)
- returnVal = ChkPrintErr(err, b);
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetDriverName:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::GetDriverName(CStr255& driverName)
- {
- driverName.Empty();
-
- String255Handle driverHandle = (String255Handle)GetString((short)kPrintDriverName);// Get current driver
-
- if (driverHandle)
- driverName.CopyFrom(**driverHandle);
- }
-
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::Update()
- {
- // Printer name may have changed… out with the old in with the new...
- fPrinterChangeLevel = fgPrinterChangeLevel;
-
- Inherited::Update();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)// Override
- {
- switch (theChange)
- {
- case mRegainControl:
- if (CheckPrinterChangeLevel() != fPrinterChangeLevel)
- {
- Invalidate();
- Changed(mPrinterChanged, this);
-
- }
- break;
-
- default:
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::JobMerge:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TMacPrintJob::JobMerge(TPrintInfo* mergeFrom)
- {
- CInMacPrint inMacPrint(this);
-
- ::PrJobMerge(((TMacPrintJob *)mergeFrom)->GetHPrint(), GetHPrint());
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::IdleProc:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- pascal void TMacPrintJob::IdleProc()
- {
- if (gJobPrintHandler)
- {
- short saveResFile = MACurResFile(); // save it so it can be restored if someone forgets
-
- GrafPtr savedPort;
- GetPort(&savedPort);
- SetPortWindowPort(gWorkPort);
-
- TPrintHandler * currentPrintHandler = TPrintHandler::gCurrPrintHandler;
- TPrintHandler::gCurrPrintHandler = NULL;// So we can focus when updating and activating windows
- Boolean printingStatus = TView::gPrinting;
- TView::gPrinting = FALSE;
-
- ++gDispatcher->fEventLevel; // Increment the event level for proper busy cursor handling
- ((TMacPrintJob*)gJobPrintHandler->fPrintInfo)->DoPrintIdling(); // Forward to the current print job handler
- --gDispatcher->fEventLevel;
-
- TPrintHandler::gCurrPrintHandler = currentPrintHandler;
- TView::gPrinting = printingStatus;
-
- SetPort(savedPort);
-
- MAUseResFile(saveResFile);
- }
- } // IdleProcForTStdPrintHandler
-
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::DoPrintIdling:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::DoPrintIdling()
- {
- const short myDlgMask = mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask | activMask;
-
- TToolboxEvent * event = gDispatcher->GetEvent(myDlgMask, 0, NULL);
- if (event)
- {
- // Workaround for LaserWriter driver bug: it tries to set GhostWindow
- // so that its status window is invisible. Unfortunately, it doesn't
- // always set it, so IsDialogEvent returns false (the status window
- // is frontmost). If ours isn't already in front, force it there.
- if ((WindowRef)fPrintDialog != FrontWindow())
- TWindow::MASelectToolboxWindow((WindowRef)fPrintDialog);// 3.5
-
- switch (event->fEventRecord.what)
- {
- case keyDown:
- {
- char ch = (char)(event->fEventRecord.message & charCodeMask);
- short keycode = (short)((event->fEventRecord.message & keyCodeMask) >> 8);
- if (((ch == '.') && event->IsCommandKeyPressed()) || ((ch == chEscape) && (keycode == kEscapeVirtualCode)))
- {
- short item = 1; // Want the 'Cancel' button
-
- // if (fPrintingCommand == cFinderPrint || fPrintingCommand == cDragPrint)
- // item = cancel; // Want the 'Cancel All' button
-
- // Flash the appropriate button
- Handle theItem;
- short itemType;
- CRect box;
- GetDialogItem(fPrintDialog, item, &itemType, &theItem, box);
-
- HiliteControl((ControlRef)theItem, 10);
-
- long dontCare;
- Delay(8, &dontCare);
-
- HiliteControl((ControlRef)theItem, 0);
-
- SetError(iPrAbort);
- gCancelAllPrinting = TRUE;
- }
- break;
- }
-
- default:
- {
- EventRecord anEventRecord = event->fEventRecord;
- DialogRef aDialog;
- short item;
- if (IsDialogEvent(&anEventRecord) && DialogSelect(&anEventRecord, &aDialog, &item) && (aDialog == fPrintDialog))
- {
- switch (item)
- {
- case 1:
- SetError(iPrAbort);// Cancel
- break;
-
- case cancel: // Cancel All Printing
- SetError(iPrAbort);
- gCancelAllPrinting = TRUE;
- break;
- }
- }
- else if (event->fEventRecord.what == mouseDown)
- {
- WindowRef aWindow;
- short itsPart = FindWindow(event->fEventRecord.where, &aWindow);
- if (itsPart == inDrag && aWindow == (WindowRef)fPrintDialog)
- {
- CRect moveBounds(-32000, -32000, 32000, 32000);
- TWindow::MADragWindow((WindowRef)fPrintDialog, event->fEventRecord.where, moveBounds);
- }
- }
- break;
- }
- }
- if (event->ShouldFreeOnCompletion())
- event = (TToolboxEvent *)FreeIfObject(event);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::PosePrintDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::PosePrintDialog(const CStr255& docName, CommandNumber aCommandNumber)
- {
- short dlgNumber;
- DialogTHndl dlogTemplate;
- short itemNo;
- Handle theItem;
- short itemType;
- CRect box;
- CStr255 itemText;
- short preDocName;
- short constTitle;
-
- FailOSErr(MAInteractWithUser());
-
- if (aCommandNumber == cFinderPrint || aCommandNumber == cDragPrint)
- {
- dlgNumber = phFinderPrintDialog;
- itemNo = 3;
- }
- else
- {
- dlgNumber = phSpoolPrintDialog;
- itemNo = 2;
- }
-
- // Can't use GetNewCenteredDialog because vertically centering the dialog may cause it
- // to interfere with the Print Manager's status windows. Therefore, leave the vertical
- // location of the dialog fixed.
-
- SetCursor(&(qd.arrow));
- gDispatcher->InvalidateMouseRegions();
- dlogTemplate = (DialogTHndl)GetResource('DLOG', dlgNumber);
- if (dlogTemplate)
- {
- CenterRectOnScreen(((CRect &)(*dlogTemplate)->boundsRect), TRUE, FALSE, FALSE);
- fPrintDialog = GetNewDialog(dlgNumber, NULL, (WindowRef) - 1);
- FailNIL(fPrintDialog);
- }
- else
- {
- #if qDebugMsg
- fprintf(stderr, "You may have forgotten to include Printing.rsrc in your .r file…\n");
- ProgramBreak("The print job dialog resource can't be found.");
- #endif
-
- FailNILResource((Handle)dlogTemplate);
- }
-
- // Substitute the document name for '<<!=>>' in 'Document “<<!=>>” is being printed'.
- // ParamText would be a lot simpler, but the Print Mgr. also uses ParamText, and
- // the substitution doesn't happen until draw time.
- GetDialogItem(fPrintDialog, itemNo, &itemType, &theItem, &box);
- if (theItem)
- {
- GetDialogItemText(theItem, itemText);
- if (ParseTitleTemplate(itemText, preDocName, constTitle) && SubstituteInTitle(itemText, docName, preDocName, constTitle))
- SetDialogItemText(theItem, itemText);
- }
-
- (*GetHPrint())->prJob.pIdleProc = pPrintIdleProc;
-
- SetWTitle((WindowRef)fPrintDialog, docName);// In case Print Mgr. needs it.
- DrawDialog(fPrintDialog);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::BanishPrintDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- void TMacPrintJob::BanishPrintDialog()
- {
- if (fPrintDialog)
- {
- if (GetWindowPort(fPrintDialog) == (CGrafPtr)qd.thePort)// Only need to invalidate focus if freed
- // dialog is the current port
- {
- gDispatcher->InvalidateFocus();
- SetPortWindowPort(gWorkPort);
- }
- DisposeDialog(fPrintDialog);
- fPrintDialog = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::ShowDocBeingPrinted:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintFinder
-
- void TMacPrintJob::ShowDocBeingPrinted(const CStr255& docName, Boolean entering)
- {
- if (entering)
- {
- fPrintDialog = GetNewDialog(phWhichDoc, NULL, (WindowRef) - 1);
- if (fPrintDialog)
- {
- SetWTitle((WindowRef)fPrintDialog, docName);
- DrawDialog(fPrintDialog);
- }
- #if qDebug
- else
- {
- CStr255 theString;
- ConcatNumber("Unable to load dialog ", phWhichDoc, theString);
- ProgramBreak(theString);
- }
- #endif
-
- }
- else
- BanishPrintDialog();
- }
-
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::GetMaxSquareResolution:
- //----------------------------------------------------------------------------------------
- void TMacPrintJob::GetMaxSquareResolution(Fixed& hRes, Fixed& vRes)
- {
- CInMacPrint inMacPrint(this);
-
- TGetRslBlk aGetRslData;
- aGetRslData.iOpCode = getRslDataOp;
- aGetRslData.iError = 0;
-
- ::PrGeneral((Ptr) & aGetRslData);
- if (GetError() == noErr)
- {
- short dpi = 0;
- for (short i = 0; i < aGetRslData.iRslRecCnt; i++)
- if (aGetRslData.rgRslRec[i].iXRsl == aGetRslData.rgRslRec[i].iYRsl)
- // only square
- dpi = (short)Max(dpi, aGetRslData.rgRslRec[i].iXRsl);
-
- hRes = dpi;
- vRes = dpi;
- }
- else
- Inherited::GetMaxSquareResolution(hRes, vRes);
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::SetResolution:
- //----------------------------------------------------------------------------------------
- void TMacPrintJob::SetResolution(Fixed hRes, Fixed vRes)
- {
- TSetRslBlk aSetRslData;
- aSetRslData.iOpCode = setRslOp;
- aSetRslData.iError = 0;
- aSetRslData.hPrint = GetHPrint();
- aSetRslData.iXRsl = hRes;
- aSetRslData.iYRsl = vRes;
-
- ::PrGeneral((Ptr) & aSetRslData);
- FailOSErr(GetError());
-
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TMacPrintJob::MaximizeResolution:
- //----------------------------------------------------------------------------------------
- void TMacPrintJob::MaximizeResolution()
- {
- // Thank you, A.D.
- CInMacPrint inMacPrint(this); // for grouping the two calls together
-
- long hRes;
- long vRes;
- GetMaxSquareResolution(hRes, vRes);
- SetResolution(hRes, vRes);
- }
-
- //========================================================================================
- // CLASS TStdPrintHandler
- //========================================================================================
- #undef Inherited
- #define Inherited TPrintHandler
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TStdPrintHandler,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TStdPrintHandler::TStdPrintHandler() :
-
- fPrintExtent(gZeroVRect),
- fViewedRect(gZeroVRect),
- fViewToQDOffset(gZeroVPt),
- fPageStrips(gZeroVPt),
- fLastStrip(VPoint(SHRT_MAX, SHRT_MAX)),
- fLastBreak(gZeroVPt),
- fQDRectToClipTo(gZeroRect),
- fQDOrigin(gZeroPt),
- fPrintInfo(NULL),
- fPrintingCommand(cNoCommand), // Will be set in DoPrintCommand
- fStartPage(1),
- fPageDirection(vSel), // Page 2 is below page 1, etc.
-
- fFinderSetup(FALSE),
- fFinderJobDialog(FALSE),
- fMinimalMargins(FALSE),
- fUseMaxResolution(FALSE),
-
- fPaperRect(gZeroVRect),
- fInkRect(gZeroVRect),
- fMarginsRect(gStdPageMargins),
- fInteriorRect(gZeroVRect),
-
- fIsValid(FALSE)
- {
- fFixedSizePages[hSel] = kFixedSize;
- fFixedSizePages[vSel] = kFixedSize;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::ChkPrintErr:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TStdPrintHandler::ChkPrintErr(OSErr& err,
- Boolean& ranOutOfSpace)
- {
- return fPrintInfo->ChkPrintErr(err, ranOutOfSpace);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PrintSpoolFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintSpool
-
- Boolean TStdPrintHandler::PrintSpoolFile(OSErr& err)
- {
- return fPrintInfo->CallPrPicFile(err);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::IStdPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- void TStdPrintHandler::IStdPrintHandler(TDocument* itsDocument,
- TView* itsView,
- Boolean itsHFixedSize,
- Boolean itsVFixedSize)
- {
- IPrintHandler(itsView); // sets fView to itsView
-
- fDocument = itsDocument;
- fFixedSizePages[hSel] = itsHFixedSize;
- fFixedSizePages[vSel] = itsVFixedSize;
-
- FailInfo fi;
- Try(fi)
- {
- if (fView)
- {
- SetDefaultPrintInfo();
-
- if (itsDocument)
- itsDocument->AttachPrintHandler(this);
-
- fView->AttachPrintHandler(this);
-
- fPrintInfo->AddDependent(this);
- }
- fi.Success();
- }
- else // Recover
- {
- // We may have failed AFTER attaching the printhandler to the view. If we were
- // to free ourself without detaching we would leave the view with a
- // reference to a freed behavior. So remove ourselves before freeing. We don't
- // have to worry about detaching from the document since that will occur
- // in our free method. In the same vein, RemoveBehavior will call SetOwner
- // which will detach us from the window.
- if (fView)
- fView->RemoveBehavior(this);
-
- Free();
-
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintClose
-
- TStdPrintHandler::~TStdPrintHandler()
- {
- Boolean dontDispose = fView != NULL;
- if (dontDispose)
- {
- // If you are freeing a print handler, it is up to you to detach it
- // from the view first.
-
- fView->DeleteAdorner(gPrintAdorner, FALSE);
- fView = NULL;
-
- if (fDocument)
- {
- fDocument->DetachPrintHandler(this);
- dontDispose = fDocument->fSharePrintInfo && (fDocument->fPrintInfo == fPrintInfo);
- }
- else
- dontDispose = FALSE;
- fDocument = NULL;
- }
-
- if (fPrintInfo)
- fPrintInfo->BanishPrintDialog();
-
- if (!dontDispose)
- fPrintInfo = (TPrintInfo *)FreeIfObject(fPrintInfo);
- fPrintInfo = NULL; // Always drop my reference
-
- if (gJobPrintHandler == this) // let's be safe
- gJobPrintHandler = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- TObject* TStdPrintHandler::Clone() // Override
- {
- MAVolatileInit(TStdPrintHandler * , aStdPrintHandler, (TStdPrintHandler *)Inherited::Clone());
- TPrintInfo * aPrintInfo;
-
- if (fPrintInfo)
- {
- aStdPrintHandler->fPrintInfo = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- aPrintInfo = (TPrintInfo *)fPrintInfo->Clone();
- aStdPrintHandler->fPrintInfo = aPrintInfo;
-
- fi.Success();
- }
- else // Recover
- {
- aStdPrintHandler->Free();
- fi.ReSignal();
- }
- }
-
- return aStdPrintHandler;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::AdornPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::AdornPage()
- {
- #if qDebug
- if (gDebugPrinting) // Print extra stuff if debugging
- {
- const short botSlop = 8;
-
- VRect thePaperRect(GetPaperRect());
- long rPlusL = thePaperRect.right + thePaperRect.left;
-
- long itsBottom = GetInkRect().bottom - botSlop;
-
- // draw the heading
- TextFont(applFont);
- TextFace(normal);
- TextSize(12);
- FontInfo theFontInfo;
- GetFontInfo(&theFontInfo);
-
- CStr255 pgStr;
- NumToString(fFocusedPage, pgStr);
- CStr255 heading = "-" + pgStr + "-";
-
- long itsWidth = StringWidth(heading);
-
- CRect theTextRect;
- theTextRect.left = (short)(rPlusL - itsWidth) / 2;
- theTextRect.top = (short)itsBottom - theFontInfo.ascent;
- theTextRect.right = (short)(theTextRect.left + itsWidth);
- theTextRect.bottom = (short)itsBottom + theFontInfo.descent;
- MADrawString(heading, theTextRect, teFlushDefault);
-
- // Additionally frame the printable area of the page if gDebugPrinting
- PenSize(1, 1);
- FrameRect(&fView->ViewToQDRect(GetInkRect()));
-
- // Frame the 'interior' of the page
- PenSize(2, 2);
- FrameRect(&fView->ViewToQDRect(GetInteriorRect()));
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::BreakFollowing: Called from fView->DoBreakFollowing(),
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VCoordinate TStdPrintHandler::BreakFollowing(VHSelect vhs,
- VCoordinate previousBreak,
- Boolean& automatic)// override
- {
- VHSelect orthoVHS = gOrthogonal[vhs];
- automatic = TRUE;
- VCoordinate newLoc = Min(previousBreak + GetViewPerPage()[orthoVHS], fPrintExtent[botRight][orthoVHS]);
-
- #if qDebugMsg
- if (newLoc <= previousBreak)
- {
- fprintf(stderr, "No advance in BreakFollowing; vhs: %1d previousBreak: %1d newLoc: %1d view size: \n", (short)vhs, previousBreak, newLoc, fPrintExtent[botRight][orthoVHS]);
- ProgramBreak("No advance in BreakFollowing");
- }
- #endif
-
- return newLoc;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::CalcPageStrips:
- //----------------------------------------------------------------------------------------
- VPoint TStdPrintHandler::CalcPageStrips()// override
- {
- VPoint pageStrips;
- // If pages are of fixed size, then simple divide the total size by the
- // page size. Otherwise, count up the page breaks one by one.
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- VHSelect ortho = gOrthogonal[vhs];
- if (fFixedSizePages[ortho])
- pageStrips[vhs] = (fPrintExtent[botRight][ortho] - fPrintExtent[topLeft][ortho] + GetViewPerPage()[ortho] - 1) / GetViewPerPage()[ortho];
- else
- {
- VCoordinate previousBreak = 0;
-
- long nStrips = 0;
- VCoordinate startLoc = fPrintExtent[topLeft][gOrthogonal[vhs]];
- VCoordinate endLoc = fPrintExtent[botRight][gOrthogonal[vhs]];
-
- VCoordinate loc = startLoc;
- Boolean automatic = TRUE;
- Boolean done = FALSE;
- while (loc < endLoc)
- {
- if (loc != startLoc)
- ++nStrips;
-
- #if qDebug
- previousBreak = loc;
- #endif
-
- loc = fView->DoBreakFollowing(vhs, loc, automatic);
-
- #if qDebug
- if (loc <= previousBreak)
- ProgramBreak("thisBreak (loc) <= previousBreak");// Thanks much to Larry T. !
- #endif
-
- }
-
- if (loc != startLoc)
- ++nStrips;
-
- pageStrips[vhs] = nStrips;
- }
- }
-
- return pageStrips;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::CalcViewPerPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- VPoint TStdPrintHandler::CalcViewPerPage()// override
- {
- return (GetPaperRect() + GetMarginsRect()).GetSize();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Invalidate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::Invalidate()
- {
- fIsValid = FALSE;
-
- //SRF get a message assigned!!! Changed(mPrinterChanged, this);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::Update()
- {
- if (!fIsValid)
- {
- fPrintInfo->Update();
-
- fIsValid = TRUE;
-
- CPoint oldDevRes(fDeviceRes);
- VRect oldPaper(fPaperRect);
- VRect oldInk(fInkRect);
- VRect oldMargins(fMarginsRect);
-
- // Store latest data from fPrintInfo into my own instance variables
- fDeviceRes = fPrintInfo->GetDeviceRes();
- fPaperRect = fPrintInfo->GetPaperRect();
- fInkRect = fPrintInfo->GetInkRect();
-
- if (fMinimalMargins)
- fMarginsRect = fInkRect - fPaperRect;
- else
- {
- fMarginsRect = VRect((oldMargins.left * fDeviceRes.h) / oldDevRes.h, (oldMargins.top * fDeviceRes.v) / oldDevRes.v, (oldMargins.right * fDeviceRes.h) / oldDevRes.h, (oldMargins.bottom * fDeviceRes.v) / oldDevRes.v);
- }
- // and while we are at it update fViewPerPage…
- fViewPerPage = fView->DoCalcViewPerPage();
-
- if ((fDeviceRes != oldDevRes) || (fPaperRect != oldPaper) || (fInkRect != oldInk) || (fMarginsRect != oldMargins))
- {
- Boolean msgSent = FALSE; // something important to our projection model changed...
- if (fDocument && fDocument->fSharePrintInfo)
- {
- CObjectIterator iter(fDocument->fViewList);
-
- for (TView * aView = (TView *)iter.FirstObject(); iter.More(); aView = (TView *)iter.NextObject())
- aView->DoPrinterChanged();
-
- msgSent = TRUE;
- }
-
- if (!msgSent)
- // didn't send msg to all views, current company included,
- // so now we need to tell must my local view
- fView->DoPrinterChanged();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::ChooseSpoolFile:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::ChooseSpoolFile(FSSpec& theSpoolFile,
- long& pagesPerSubjob)
- {
- // Default choices tell Print Manager to use its standard choice algorithm
- theSpoolFile.name[0] = 0;
- theSpoolFile.vRefNum = 0;
- theSpoolFile.parID = 0;
-
- // Print Shop suggests attempting to print entire document. If it
- // runs out of space, then PerformPrinting will retry with a
- // smaller number of pages.
- pagesPerSubjob = GetDefaultSubJobSize();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetPaperRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TStdPrintHandler::GetPaperRect()
- {
- Update();
-
- return fPaperRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetInkRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TStdPrintHandler::GetInkRect()
- {
- Update();
-
- return fInkRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetMarginsRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TStdPrintHandler::GetMarginsRect()
- {
- Update();
-
- return fMarginsRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetInteriorRect:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VRect TStdPrintHandler::GetInteriorRect()
- {
- Update();
-
- return fInteriorRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetViewPerPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VPoint TStdPrintHandler::GetViewPerPage()
- {
- Update();
-
- return fViewPerPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoScriptCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TStdPrintHandler::DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- Boolean wasHandled;
-
- if (aCommandNumber == cPrint)
- {
- Boolean setupSuccess;
- // if user interaction is allowed, bring up the job dialog. If no UI is allowed,
- // perform a print one.
- if (MAInteractWithUser() == noErr)
- setupSuccess = PoseJobDialog();
- else
- {
- aCommandNumber = cPrintOne;
- setupSuccess = SetupPrintOne(aCommandNumber);
- }
-
- if (setupSuccess)
- Print(aCommandNumber);
- wasHandled = TRUE;
- }
- else
- wasHandled = Inherited::DoScriptCommand(aCommandNumber, message, reply);
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::DoMenuCommand(CommandNumber aCommandNumber)// override
- {
- if (!DoPrintCommand(aCommandNumber))
- Inherited::DoMenuCommand(aCommandNumber);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoPrintCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TStdPrintHandler::DoPrintCommand(CommandNumber aCommandNumber)
- {
- Boolean handled = TRUE; // assume we handle it
-
- fPrintingCommand = aCommandNumber;
-
- switch (aCommandNumber)
- {
- case cPageSetup:
- PosePageSetupDialog(TRUE);
- break;
-
- case cPrint:
- {
- TPrintCommand * aPrintCommand = new TPrintCommand;
- aPrintCommand->IPrintCommand(aCommandNumber, this);
- aPrintCommand->fUseAppleEvent = TRUE;
- if (fOwner)
- fOwner->PostCommand(aPrintCommand);
- else
- gDispatcher->PostCommand(aPrintCommand);
- }
- break;
-
- case cPrintOne:
- {
- TPrintCommand * aPrintCommand = new TPrintCommand;
- aPrintCommand->IPrintCommand(aCommandNumber, this);
- // aPrintCommand->fUseAppleEvent = TRUE; // no way to record this
- if (fOwner)
- fOwner->PostCommand(aPrintCommand);
- else
- gDispatcher->PostCommand(aPrintCommand);
- }
- break;
-
- case cShowBreaks: // Toggle state of "Show Breaks"
- fShowBreaks = !fShowBreaks;
- InvalPageFeedback(); // force redraw of area the breaks did or will occupy
- break;
-
- case cFinderPrint: // handle Finder printing
- if (SetupForFinder(aCommandNumber))
- gFinderPrintingProceed = Print(cFinderPrint);
- break;
-
- case cDragPrint: // handle Drag printing
- if (SetupPrintOne(aCommandNumber))
- gFinderPrintingProceed = Print(cDragPrint);
- break;
-
- default:
- handled = FALSE;
- break;
- }
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::DoSetupMenus() // override
- {
- Inherited::DoSetupMenus();
-
- DoSetupPrintMenus();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoSetupPrintMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::DoSetupPrintMenus()
- {
- if (gCouldPrint && fView && !MemSpaceIsLow())
- {
- Enable(cPageSetup, TRUE);
- Enable(cPrint, TRUE);
- Enable(cPrintOne, TRUE);
- Enable(cPrintSelection, fView != NULL);
- }
- EnableCheck(cShowBreaks, TRUE, fShowBreaks);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DrawPrintFeedback: Draws page breaks and page numbers
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TStdPrintHandler::DrawPrintFeedback(const VRect& area)// override
- {
- #if qDebug
- fView->AssumeFocused();
- #endif
-
- if (fShowBreaks || gDebugPrinting)
- {
- SetPrintExtent(); // Make sure print extent is accurate before starting
-
- #if qDebug
- if (gDebugPrinting) // Now draw Page numbers in the corners of pages, if desired
- {
- TextStyle pageNumStyle;
-
- SetTextStyle(pageNumStyle, applFont, bold, 9, gRGBBlack);
- SetPortTextStyle(pageNumStyle);
- }
- #endif
-
- SetPenState(&gBreaksPenState);
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- VHSelect orthoVHS = gOrthogonal[vhs];
- short whichBreak = 0;
- VCoordinate previousBreak = 0;
- Boolean automatic = TRUE;
- Boolean done = FALSE;
-
- VCoordinate startLoc = fPrintExtent[topLeft][gOrthogonal[vhs]];
- VCoordinate endLoc = fPrintExtent[botRight][gOrthogonal[vhs]];
- VCoordinate loc = startLoc;
-
- while ((loc < endLoc) && !done)
- {
- if (loc != startLoc)
- {
- if (loc > area[botRight][orthoVHS])
- done = TRUE;
- else
- {
- ++whichBreak;
- if (loc > (area[topLeft][orthoVHS] - ((CPoint &)gBreaksPenState.pnSize)[orthoVHS]))
- fView->DoDrawPageBreak(vhs, whichBreak, loc, automatic);
- done = FALSE;
- }
- }
-
- #if qDebug
- previousBreak = loc;
- #endif
-
- loc = fView->DoBreakFollowing(vhs, loc, automatic);
-
- #if qDebug
- if (loc <= previousBreak)
- ProgramBreak("thisBreak (loc) <= previousBreak");// Thanks much to Larry T. !
- #endif
-
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DrawPageBreak:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- #if qDebug
- void TStdPrintHandler::DrawPageBreak(VHSelect vhs,
- long whichBreak,
- VCoordinate loc,
- Boolean) // override
- #else
- void TStdPrintHandler::DrawPageBreak(VHSelect vhs,
- long /* whichBreak */,
- VCoordinate loc,
- Boolean) // multiple declarations to eliminate compiler warnings
- #endif
-
- {
- VPoint vPt;
- vPt[gOrthogonal[vhs]] = loc;
-
- // Get the origin of the view, while accounting for any translation.
- vPt[vhs] = fView->GetExtent()[topLeft][vhs];
-
- CPoint qdStartPt = fView->ViewToQDPt(vPt);
- vPt[vhs] = fView->fSize[vhs];
- CPoint qdEndPt = fView->ViewToQDPt(vPt);
- qdEndPt[vhs] -= ((CPoint &)gBreaksPenState.pnSize)[vhs];
- // Subtract the pen size _AFTER__ converting to qd coords. Thank you L.J.!
-
- if (fShowBreaks)
- {
- MoveToPt(qdStartPt);
- LineToPt(qdEndPt);
- }
-
- #if qDebug
- if (gDebugPrinting)
- if (vhs == hSel)
- {
- VCoordinate hLoc;
- CStr255 aString;
- FontInfo theFontInfo;
- CRect theTextRect;
-
- for (long i = 0; i <= fPageStrips.v; ++i)
- {
- if (i == 0)
- hLoc = 0;
- else
- GetBreakCoord(vSel, i, hLoc);
-
- GetFontInfo(&theFontInfo);
-
- NumToString(StripToPage(VPoint(whichBreak - 1, i)), aString);
- // top computed based on the bottom - text height
- theTextRect = CRect((short)hLoc + 3, qdStartPt.v - 3 - theFontInfo.ascent, (short)hLoc + 3 + StringWidth(aString), qdStartPt.v - 3 + theFontInfo.descent);
- MADrawString(aString, theTextRect, teFlushDefault);
-
- NumToString(StripToPage(VPoint(whichBreak, i)), aString);
- // top computed based on the bottom - text height
- theTextRect = CRect((short)hLoc + 3, qdEndPt.v + 10 - theFontInfo.ascent, (short)hLoc + 3 + StringWidth(aString), qdEndPt.v + 10 + theFontInfo.descent);
- MADrawString(aString, theTextRect, teFlushDefault);
-
- NumToString(StripToPage(VPoint(whichBreak - 1, i - 1)), aString);
- // top computed based on the bottom - text height
- theTextRect = CRect((short)hLoc - StringWidth(aString) - 3, qdStartPt.v - 3 - theFontInfo.ascent, (short)hLoc - 3, qdStartPt.v - 3 + theFontInfo.descent);
- MADrawString(aString, theTextRect, teFlushDefault);
-
- NumToString(StripToPage(VPoint(whichBreak, i - 1)), aString);
- // top computed based on the bottom - text height
- theTextRect = CRect((short)hLoc - StringWidth(aString) - 3, qdEndPt.v + 10 - theFontInfo.ascent, (short)hLoc - 3, qdEndPt.v + 10 + theFontInfo.descent);
- MADrawString(aString, theTextRect, teFlushDefault);
- }
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DrawPageInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::DrawPageInterior()
- {
- // i.e., by default, the same code used for drawing on the screen
- fView->HandleDraw(fView->QDToViewRect(fQDRectToClipTo));
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- Boolean TStdPrintHandler::Focus() // override
- {
- Boolean returnVal = FALSE;
-
- GrafPtr printingPort = fPrintInfo->GetJobPort();
- if (printingPort)
- {
- SetPort(printingPort);
-
- SetOrigin(fQDOrigin.h, fQDOrigin.v);
- CRect clipTo = fQDRectToClipTo;
- ClipRect(clipTo);
- returnVal = TRUE;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::FocusOnBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::FocusOnBorder()
- {
- VRect rectToClipTo(GetInkRect());
-
- // Only works for newer LaserWriter drivers
- fQDOrigin = rectToClipTo[topLeft].ToPoint();
- SetOrigin(fQDOrigin.h, fQDOrigin.v);
- fView->InvalidateCoordinates(); // Need to update the coordinates to reflect the
- // change in the port's origin.
-
- fQDRectToClipTo = fView->ViewToQDRect(rectToClipTo);
- ClipRect(&fQDRectToClipTo);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::FocusOnInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::FocusOnInterior() // override
- {
- const short kMaxOriginFixup = 1024;
-
- VPoint theVOrigin;
-
- VRect aRect = GetInkRect();
- VPoint theOrigin = aRect[topLeft];
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- if (fView->fSize[vhs] > kMaxCoord)
- theVOrigin[vhs] = gPageOffset[vhs];
- else
- {
- theVOrigin[vhs] = 0;
- theOrigin[vhs] += gPageOffset[vhs];
- }
- aRect[topLeft][vhs] += gPageOffset[vhs];
- aRect[botRight][vhs] += gPageOffset[vhs];
- }
-
- if (VRect(-kMaxCoord, -kMaxCoord, kMaxCoord, kMaxCoord).Contains(fView->GetExtent()))
- {
- fQDOrigin = theOrigin.ToPoint();
- fViewToQDOffset = theVOrigin;
- }
- else
- {
- CPoint deltaOrigin = CPoint((short)(theVOrigin.h % kMaxOriginFixup), (short)(theVOrigin.v % kMaxOriginFixup));
- fViewToQDOffset = theVOrigin - VPoint(deltaOrigin);
- fQDOrigin = deltaOrigin;
- }
- SetOrigin(fQDOrigin.h, fQDOrigin.v);
- fView->InvalidateCoordinates(); // Need to update the coordinates to reflect the
- // change in the port's origin.
-
- // Clip the page to the macroIntersection of the visible part of the view and the
- // printable area of the page. Note that in some cases (e.g., a WYSIWYG
- // word processor which showed the complete page margin) parts of
- // the interior might lie outside theInk. We must clip to theInk to
- // avoid slowing down PostScript printers.
- fQDRectToClipTo = fView->ViewToQDRect(fViewedRect & aRect);
- ClipRect(&fQDRectToClipTo);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetDefaultSubJobSize:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TStdPrintHandler::GetDefaultSubJobSize()
- {
- return iPFMaxPgs;
- //SRF - is there any subjobbing necessary with GX, ever?
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetQDOrigin:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- CPoint TStdPrintHandler::GetQDOrigin() // override
- {
- return fQDOrigin;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetViewToQDOffset:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- VPoint TStdPrintHandler::GetViewToQDOffset()// override
- {
- return fViewToQDOffset;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetBreakCoord:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::GetBreakCoord(VHSelect vhs,
- long whichBreak,
- VCoordinate& loc)
- {
- Boolean automatic;
- long startBreak;
- VHSelect orthoVHS;
- VCoordinate previousBreak = 0;
-
-
- orthoVHS = gOrthogonal[vhs];
- if (fFixedSizePages[orthoVHS])
- loc = fPrintExtent[topLeft][orthoVHS] + GetViewPerPage()[orthoVHS] * whichBreak;
- else if (whichBreak == fLastStrip[vhs])
- loc = fLastBreak[vhs];
- else
- {
- if (whichBreak > fLastStrip[vhs])
- {
- startBreak = fLastStrip[vhs] + 1;
- loc = fLastBreak[vhs];
- }
- else
- {
- startBreak = 1;
- loc = fPrintExtent[topLeft][gOrthogonal[vhs]];
- }
-
- for (long i = startBreak; i <= whichBreak; ++i)
- {
- #if qDebug
- previousBreak = loc;
- #endif
-
- loc = fView->DoBreakFollowing(vhs, loc, automatic);
-
- #if qDebug
- if (loc <= previousBreak)
- ProgramBreak("thisBreak (loc) <= previousBreak");
- #endif
-
- }
- }
- loc = Min(loc, fPrintExtent[botRight][orthoVHS]);
-
- fLastStrip[vhs] = whichBreak;
- fLastBreak[vhs] = loc;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetDocName:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- CStr255 TStdPrintHandler::GetDocName()
- {
- CStr255 docName;
-
- if (fDocument)
- fDocument->GetTitle(docName);
-
- if (docName.IsEmpty())
- {
- TWindow * aWindow = fView->GetWindow();
- if (aWindow)
- aWindow->GetTitle(docName);
- }
-
- #if qDebug
- if (docName.IsEmpty())
- ProgramBreak("GetDocName can't get a document or window name");
- #endif
-
- return docName;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintMain
-
- TPrintInfo* TStdPrintHandler::GetPrintInfo()
- {
- return fPrintInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::InstallMargins:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::InstallMargins(const VRect& newMargins,
- Boolean areMinimalMargins)
- {
- fMinimalMargins = areMinimalMargins;
-
- if (fMinimalMargins)
- {
- VRect theInkRect = GetInkRect();
- fInteriorRect = theInkRect;
- fMarginsRect = theInkRect - GetPaperRect();
- }
- else
- {
- VRect theInterior = GetPaperRect() + newMargins;
- if (theInterior.Empty())
- {
- #if qDebug
- if (gDebugPrinting)
- fprintf(stderr, "margins too big for paper!\n");
- #endif
-
- VRect copyMargins(newMargins);
-
- MarginsTooBig(copyMargins);
- InstallMargins(copyMargins, areMinimalMargins);// try again
- return;
- }
- fMarginsRect = newMargins;
- fInteriorRect = theInterior;
- }
- Invalidate();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::MarginsTooBig:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::MarginsTooBig(VRect& margins)
- {
- // if you wanted, you could put up an alert here, or change the margins differently.
- // We'll set the margins to the minimal amount, as they would be set with minimal margins
-
- margins = GetInkRect() - GetPaperRect();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::InvalPageFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::InvalPageFeedback()
- {
- if (ShowsOnScreen())
- fView->ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::LocatePageInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- VPoint TStdPrintHandler::LocatePageInterior(long /* pageNumber */)// override
- {
- return GetPaperRect()[topLeft] + GetMarginsRect()[topLeft];
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::MaxPageNumber:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- long TStdPrintHandler::MaxPageNumber() // override
-
- {
- // respect the maximum page number supported by the printing manager
- //••• SRF need to call back to TPrintinfo for the max page number
- Update(); // Ensure the fPageStrips is valid!!
- return Min(fStartPage + (fPageStrips.v * fPageStrips.h) - 1, iPrPgMax);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::OneSubJob:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TStdPrintHandler::OneSubJob(long subjobFirstPage,
- long subjobLastPage,
- long minFromPage,
- long maxToPage,
- Boolean justSpool,
- Boolean /* partialJob */,
- Boolean& ranOutOfSpace,
- long& lastPageTried)
- {
- MAVolatileInit(Boolean, volatileProceed, TRUE);
-
- #if qDebugMsg
- if (gDebugPrinting)
- fprintf(stderr, "OneSubJob entered for pages %1d through %1d, proceed=%s\n", subjobFirstPage, subjobLastPage, volatileProceed ? "true" : "false");
- #endif
-
- ranOutOfSpace = FALSE;
- lastPageTried = subjobFirstPage - 1;
-
- long firstPage = 1;
- long lastPage = subjobLastPage - subjobFirstPage + 1;
- long numPages = lastPage - firstPage + 1;
- fPrintInfo->SetPrintPages(firstPage, lastPage, minFromPage, maxToPage);
-
- long numberOfTimesToImage = fPrintInfo->IsSpooling() ? 1 : fPrintInfo->GetPrintCopies();
-
- fPrintInfo->StartJob(GetDocName(), numPages);
-
- OSErr err;
- if (volatileProceed)
- volatileProceed = ChkPrintErr(err, ranOutOfSpace);
-
- if (volatileProceed)
- {
- fView->InvalidateFocus();
- SetPort(fPrintInfo->GetJobPort());
-
- gCurrPrintHandler = this;
- TView::gPrinting = TRUE;
-
- fView->BeInPort(fPrintInfo->GetJobPort());
-
- if (!fView->Focus())
- {
- #if qDebug
- ProgramBreak("Can't focus view while printing");
- #endif
- }
-
- for (long pass = 1; pass <= numberOfTimesToImage; ++pass)
- for (long aPageNumber = subjobFirstPage; aPageNumber <= subjobLastPage; ++aPageNumber)
- if (volatileProceed)
- {
- lastPageTried = aPageNumber;
-
- FailInfo fi;
- Try(fi)
- {
- PrintPage(aPageNumber);
-
- fi.Success();
- }
- else // Recover
- {
- volatileProceed = FALSE;
- err = fi.error; // pass along client's error code
- }
- if (volatileProceed)
- volatileProceed = ChkPrintErr(err, ranOutOfSpace);
- }
-
- TView::gPrinting = FALSE;
- gCurrPrintHandler = NULL;
- fView->InvalidateFocus();
- fView->BeInPort(fView->GetGrafPort());
- }
-
- fPrintInfo->FinishJob(); // This will close the port!
-
- if (volatileProceed)
- volatileProceed = ChkPrintErr(err, ranOutOfSpace);
-
- if (!ranOutOfSpace)
- {
- if (volatileProceed)
- {
- if (fPrintInfo->IsSpooling() && !justSpool)
- volatileProceed = PrintSpoolFile(err);
- }
- if ((!volatileProceed) && (err != iPrAbort))
- Failure(err, 0);
- }
-
- return volatileProceed;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PageToStrip:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VPoint TStdPrintHandler::PageToStrip(long pageNumber)
- {
- long normalizedPageNum;
- VHSelect ortho;
- VPoint strip;
-
- normalizedPageNum = pageNumber - fStartPage + 1;
-
- ortho = gOrthogonal[fPageDirection];
-
- VPoint pageStrip;
- pageStrip[ortho] = (normalizedPageNum - 1) / fPageStrips[ortho];
- pageStrip[fPageDirection] = normalizedPageNum - ((pageStrip[ortho]) * fPageStrips[ortho]) - 1;
-
- return pageStrip;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PoseJobDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
-
- Boolean TStdPrintHandler::PoseJobDialog()
- {
- // PrepareForDialog;
- Boolean proceed = fPrintInfo->CallJobDialog();
-
- OSErr err;
- Boolean b;
- if (proceed)
- proceed = ChkPrintErr(err, b);
-
- // Rectify the range as a public service if needed
- long firstPage;
- long lastPage;
- long minPage;
- long maxPage;
- fPrintInfo->GetPrintPages(firstPage, lastPage, minPage, maxPage);
- if (firstPage > lastPage)
- fPrintInfo->SetPrintPages(firstPage, lastPage, minPage, maxPage);
-
- gDispatcher->UpdateAllWindows();
-
- return proceed;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PosePageSetupDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintActual
- // Needs to be here because it may be called from Print
-
- Boolean TStdPrintHandler::PosePageSetupDialog(Boolean isUndoable)
- {
- Boolean returnVal = TRUE; // proceed
-
- // Must setup command before putting up page setup dialog because the
- // command records the current print record to make it undoable.
- TPrintStyleChangeCommand * aPrintStyleChangeCommand = new TPrintStyleChangeCommand;
- aPrintStyleChangeCommand->IPrintStyleChangeCommand(this, isUndoable);
-
- // Put up the Page Setup Dialog
- returnVal = fPrintInfo->CallStyleDialog();
-
- if (returnVal) // User specified a change
- {
- aPrintStyleChangeCommand->fNewPrintInfo->SetFrom(fPrintInfo);
- if (fView)
- fView->PostCommand(aPrintStyleChangeCommand);
- else
- gDispatcher->PostCommand(aPrintStyleChangeCommand);
- }
- else // User did not specify a change
- aPrintStyleChangeCommand = (TPrintStyleChangeCommand *)FreeIfObject(aPrintStyleChangeCommand);
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Print:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TStdPrintHandler::Print(CommandNumber itsCommandNumber)// override
- {
- Boolean active = TRUE;
-
- #if qGXPrinting
- active = !gUsingGXPrinting;
- #endif
- CInMacPrint inMacPrint(fPrintInfo, fPrintInfo, active);
-
- gCancelAllPrinting = FALSE;
-
- SetPrintExtent(); // Make sure we've got the right area.
-
- FailInfo fi;
- Try(fi)
- {
- Boolean proceedWithJob = TRUE;
- Boolean justSpool = (itsCommandNumber == cPrintToFile);
-
- gJobPrintHandler = this; // be visible to the idleProc
-
- VPoint pageStrips;
- fPageStrips = fView->DoCalcPageStrips();
-
- long firstPage;
- long lastPage;
- long aMinPage;
- long aMaxPage;
- fPrintInfo->GetPrintPages(firstPage, lastPage, aMinPage, aMaxPage);
- if (lastPage == 0)
- lastPage = aMaxPage;
- firstPage = Max(firstPage, fStartPage);
- lastPage = Min(lastPage, MaxPageNumber());
-
- if (lastPage < firstPage)
- {
- OSErr anErr;
- anErr = MAInteractWithUser();
- if (anErr == noErr)
- anErr = Alert(phNoPages, NULL);
- else if (anErr == errAENoUserInteraction)
- FailOSErr(errNoPagesToPrint);
- else
- FailOSErr(anErr);
- }
- else
- {
- long pagesPerSubjob = GetDefaultSubJobSize();
- long totalPages = lastPage - firstPage + 1;
-
- if (fPrintInfo->IsSpooling())
- {
- FSSpec spoolFile;
- ChooseSpoolFile(spoolFile, pagesPerSubjob);
- // if justSpool is true, then the spool filename and vRefNum will already
- // have been stuffed into the prJob record before this method is called
- if (!justSpool && spoolFile.name[0])
- fPrintInfo->SetSpoolFile(spoolFile);;
- }
-
- long lastPrinted = firstPage - 1;
-
- pagesPerSubjob = Min(pagesPerSubjob, totalPages);
-
- fPrintInfo->PosePrintDialog(GetDocName(), itsCommandNumber);
-
- FailInfo innerfi;
- Try(innerfi)
- {
- do
- {
- long firstSubJobPage = lastPrinted + 1;
- Boolean ranOutOfSpace = FALSE;
- long lastAttempted;
- proceedWithJob = OneSubJob(firstSubJobPage, Min(firstSubJobPage + pagesPerSubjob - 1, lastPage), fStartPage, MaxPageNumber(), justSpool, (pagesPerSubjob < totalPages), ranOutOfSpace, lastAttempted);
- if (proceedWithJob)
- lastPrinted = lastAttempted;
- if (ranOutOfSpace)
- {
- pagesPerSubjob = lastAttempted - 1 - firstSubJobPage;
- proceedWithJob = TRUE;
- }
- } while ((lastPrinted != lastPage) && (pagesPerSubjob >= 1) && proceedWithJob);
-
- if (pagesPerSubjob < 1)
- Failure(errSpooling, 0);
- innerfi.Success();
- }
- else // recover
- {
- fPrintInfo->BanishPrintDialog();
- innerfi.ReSignal();
- }
- fPrintInfo->BanishPrintDialog();
- }
- gJobPrintHandler = NULL;
- fi.Success();
- }
- else // Recover
- {
- // Certain Print Manager errors should not result in any alert,
- // since the Print Manager will have already put one up.
- // !!! sure would be nice if there were constants for these in the headers!
- if ((fi.error >= -8160) && (fi.error <= -8150))
- Failure(0, messagePrintFailed);
- if (fi.message == 0)
- gErrorParm3 = GetDocName();
- FailNewMessage(fi.error, fi.message, messagePrintFailed);
- }
-
- return !gCancelAllPrinting;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PrinterChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::PrinterChanged() // override
- {
- fView->DoPagination();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PrintPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::PrintPage(long aPageNumber)// Print a single page
- {
- SetPage(aPageNumber); // gets gPage set up correctly for coordinate transformations
-
- FailInfo fi;
- Try(fi)
- {
- #if qDebug
- GrafPtr aPort;
- #endif
-
- fPrintInfo->StartPage(aPageNumber);
- FailOSErr(fPrintInfo->GetError());
-
- FocusOnInterior();
- DrawPageInterior();
- #if qDebug
- GetPort(&aPort);
- if (aPort != fPrintInfo->GetJobPort())
- ProgramBreak("The view's DrawPageInterior method changed the grafPort");
- #endif
-
- FailOSErr(fPrintInfo->GetError());
- FocusOnBorder();
- AdornPage();
- FailOSErr(fPrintInfo->GetError());
-
- fi.Success();
- }
- else // Recover
- {
- fPrintInfo->FinishPage();
- fi.ReSignal();
- }
- fPrintInfo->FinishPage();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::RedoPageBreaks:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- // Called from fView.DoPagination.
- void TStdPrintHandler::RedoPageBreaks() // override
- {
- Boolean worryAboutBreaks = (fView->GetGrafPort()) && gInitialized && (fShowBreaks || gDebugPrinting);
-
- if (worryAboutBreaks)
- InvalPageFeedback(); // invalidate old page breaks, if relevant
-
- SetPrintExtent();
- VRect oldInterior(GetInteriorRect());
- VPoint oldViewPerPage(GetViewPerPage());
-
- SetMargins(); // will synch with fViewPerPage automatically
-
- SetPageInterior(kUsualPages);
- VRect newInterior = GetInteriorRect();
-
- #if qDebug
- if (gDebugPrinting)
- if (oldInterior != newInterior)
- ProgramBreak("Setting new interior");
- #endif
-
- if (oldInterior != newInterior)
- fView->PageInteriorChanged(newInterior);
-
- #if qDebug
- if (gDebugPrinting)
- if (oldViewPerPage != GetViewPerPage())
- ProgramBreak("Setting new view per page");
- #endif
-
- if ((oldInterior != newInterior) || (oldViewPerPage != GetViewPerPage()))
- fView->AdjustFrame();
-
- fPageStrips = fView->DoCalcPageStrips();
-
- if (worryAboutBreaks)
- InvalPageFeedback(); // force redraw of new page breaks, if relevant
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::Reset:
- //----------------------------------------------------------------------------------------
- void TStdPrintHandler::Reset()
- {
- if (fPrintInfo)
- fPrintInfo->SetToDefault();
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetPrintExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::SetPrintExtent()
- {
- VRect printExtent(fView->GetPrintExtent());
-
- // Make sure the bottom or right is not smaller than the top or left.
- // This can happen when views are being created and before the window
- // has been resized to its actual size.
- printExtent.bottom = Max(printExtent.bottom, printExtent.top);
- printExtent.right = Max(printExtent.right, printExtent.left);
- fPrintExtent = printExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetDefaultPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- void TStdPrintHandler::SetDefaultPrintInfo()
- {
- Boolean havePrintInfo = FALSE;
-
- if (fDocument && fDocument->fSharePrintInfo)
- fPrintInfo = NULL;
- else
- fPrintInfo = (TPrintInfo *)FreeIfObject(fPrintInfo);
-
- if (fView)
- {
- if (fDocument && (fDocument->fSharePrintInfo && fDocument->fPrintInfo))
- {
- fPrintInfo = fDocument->fPrintInfo;
- havePrintInfo = TRUE;
- }
- }
-
- if (!havePrintInfo)
- {
- fPrintInfo = (TPrintInfo*)gDefaultPrintInfo->Clone();
- Reset();
- }
-
- FailInfo fi; // this will fail if no printer selected, so allow the app to still run
- Try(fi)
- {
- if (fUseMaxResolution)
- fPrintInfo->MaximizeResolution();
-
- fi.Success();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetMargins:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::SetMargins()
- {
- InstallMargins(GetMarginsRect(), fMinimalMargins);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::SetPage(long aPageNumber)
- {
- fFocusedPage = aPageNumber;
- VPoint strip(PageToStrip(aPageNumber));
-
- VRect viewedRect;
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- GetBreakCoord(gOrthogonal[vhs], strip[vhs], viewedRect[topLeft][vhs]);
- GetBreakCoord(gOrthogonal[vhs], strip[vhs] + 1, viewedRect[botRight][vhs]);
- }
-
- SetPageInterior(aPageNumber);
- fView->DoSetPageOffset(viewedRect[topLeft]);
- fViewedRect = viewedRect;
-
- #if qDebugMsg
- if (gDebugPrinting)
- fprintf(stderr, "pg #: %1d; coord = %s Page Interior: %s\n", aPageNumber, (const char*)viewedRect[topLeft], (const char*)GetInteriorRect());
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetPageInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintNonRes
-
- void TStdPrintHandler::SetPageInterior(long pageNumber)// override
- {
- VPoint pegPoint(LocatePageInterior(pageNumber));
-
- fInteriorRect = VRect(pegPoint, pegPoint + GetViewPerPage());
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetPageOffset:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintImage
-
- void TStdPrintHandler::SetPageOffset(const VPoint& coord)// override
- {
- gPageOffset = coord - GetInteriorRect()[topLeft];
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetupForFinder:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintFinder
-
- Boolean TStdPrintHandler::SetupForFinder(CommandNumber /* aCommandNumber */) // override
- {
- Boolean proceed = TRUE;
-
- if (fFinderSetup)
- proceed = PosePageSetupDialog(FALSE);
-
- if (proceed)
- {
- fPrintInfo->ShowDocBeingPrinted(GetDocName(), TRUE);
-
- if (fFinderJobDialog || !gFinderPrintInfo)
- {
- proceed = PoseJobDialog();
-
- if (proceed)
- {
- // Put into gFinderPrintInfo, in case next document needs it
- if (!gFinderPrintInfo)
- gFinderPrintInfo = NewTPrintInfo();
-
- gFinderPrintInfo->SetFrom(fPrintInfo);
- }
- }
- else
- fPrintInfo->JobMerge(gFinderPrintInfo);
-
- fPrintInfo->ShowDocBeingPrinted(GetDocName(), FALSE);
- }
-
- return proceed;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SetupPrintOne:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TStdPrintHandler::SetupPrintOne(CommandNumber aCommandNumber)
- {
- // Call PrValidate to 1) make sure the record is OK, and
- // 2) Get the LaserWriter driver to get the name of the front window.
-
- fPrintInfo->ClearError();
- fPrintInfo->SetPrintPages(fStartPage, MaxPageNumber(), fStartPage, MaxPageNumber());
-
- if (aCommandNumber == cDragPrint && gTargetPrinter.name[0])
- fPrintInfo->SetTargetPrinter(gTargetPrinter);
-
- return TRUE; // Should always be able to continue from here
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::ShowsOnScreen:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TStdPrintHandler::ShowsOnScreen()
- {
- return fView ? fView->IsVisible() : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::StripToPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- long TStdPrintHandler::StripToPage(VPoint pageStrip)
- {
- VHSelect ortho = gOrthogonal[fPageDirection];
-
- return pageStrip[fPageDirection] * fPageStrips[ortho] + pageStrip[ortho] + fStartPage;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TStdPrintHandler::DoUpdate(ChangeID theChange,
- TObject* /*changedObject*/ ,
- TObject* /*changedBy*/ ,
- TDependencySpace*/*dependencySpace*/ )// Override
- {
- switch (theChange)
- {
- case mPrintInfoChanged:
- Boolean wasValid = fIsValid;
- Invalidate();
-
- if (fShowBreaks || wasValid) // someone probably wants to see this
- Update();
-
- break;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::TerminateUPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TStdPrintHandler::TerminateUPrinting()
- {
- #if qGXPrinting
- OSErr printingErr = noErr;
- if (gUsingGXPrinting)
- {
- printingErr = ::GXExitPrinting();
- gUsingGXPrinting = FALSE;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::PrepareForFinderPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TStdPrintHandler::PrepareForFinderPrinting(const FSSpec* targetPrinter)
- {
- // If we have previously done a finder print we need to toss the old print information
- // or we won't ask the user for some new stuff.
- gFinderPrintInfo = (TPrintInfo *)FreeIfObject(gFinderPrintInfo);
-
- gTargetPrinter.name[0] = 0;
-
- if (targetPrinter)
- gTargetPrinter = *targetPrinter;
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::DispatcherIsAvailable:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TStdPrintHandler::DispatcherIsAvailable()
- {
- if (gDispatcher && gDefaultPrintInfo)
- gDispatcher->AddDependent(gDefaultPrintInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::GetSavePrintInfoSize:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- long TStdPrintHandler::GetSavePrintInfoSize(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork)
- {
- return itsPrintInfo->GetSize(useRsrcFork && itsFile->HasRsrcFork());
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::SavePrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TStdPrintHandler::SavePrintInfo(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork)
- {
- if (useRsrcFork && itsFile->HasRsrcFork())
- {
- if (itsFile->IsRsrcForkOpen())
- {
- short saveRefNum = itsFile->UseResource();
- if (ResError() == noErr)
- {
-
- if (itsPrintInfo->IsSetToDefault())
- {
- //
- // PrintInfo matches default for printer, User hasn't expressed any
- // specific preference. Don't write the resource so that it will be
- // default next time as well (Not just needing validation). Remove
- // any resource if present
- //
- // NOTE: that we don't do any of this if the print info is going in
- // the data fork b/c we don't have any standardized way of identifying
- // the print info and wouldn't know how to test for its presence when
- // opening the document later.
- //
- Handle printResource = NULL;
-
- short idx;
- #if qGXPrinting
- if (gUsingGXPrinting)
- idx = kFirstGXFormatIndex; // Try a GX Format record first
- else
- #endif
- idx = kFirstMacPrintFormatIndex;
-
- for (; idx >=0; --idx)
- {
- short numResources = Count1Resources(kPrintResType[idx]);
-
- if (numResources) // Any at all?
- {
- // Try preferred ID first
- printResource = Get1Resource(kPrintResType[idx], kPrintResNumber[idx]);
-
- // Try any ID next
- if (!printResource)
- printResource = Get1IndResource(kPrintResType[idx], 1);
-
- if (printResource)
- {
- RemoveResource(printResource);
- printResource = NULL;
- }
- }
- }
- }
- else
- {
- MAVolatileInit(THandleStream*, aHandleStream, NULL);
- MAVolatileInit(Handle, aHandle, NULL);
-
- FailInfo innerfi;
- Try(innerfi)
- {
- aHandleStream = new THandleStream;
- aHandle = NewPermHandle(256);
- aHandleStream->IHandleStream(aHandle, 256);
-
- itsPrintInfo->WriteTo(aHandleStream);
-
- aHandleStream = (THandleStream *)FreeIfObject(aHandleStream);
-
- short idx;
- #if qGXPrinting
- if (gUsingGXPrinting)
- idx = kFirstGXFormatIndex; // Try a GX Format record first
- else
- #endif
- idx = kFirstMacPrintFormatIndex;
-
- MAAddResource(aHandle, kPrintResType[idx], kPrintResNumber[idx], gEmptyString);
- FailResError();
-
- WriteResource(aHandle);
- ReleaseResource(aHandle);
-
- innerfi.Success();
- }
- else
- {
- aHandleStream = (THandleStream *)FreeIfObject(aHandleStream);
- aHandle = DisposeIfHandle(aHandle);
- innerfi.ReSignal();
- }
- }
-
- MAUseResFile(saveRefNum);
- }
- }
- }
- else
- {
- MAVolatileInit(TFileStream*, itsFileStream, new TFileStream);
- itsFileStream->IFileStream(itsFile);
-
- FailInfo fi;
- Try(fi)
- {
- // This should be changed to have the count in the file before the data.
- // And to identify the type of print record
-
- //••••••• ASSUME WE'RE STORING/RETRIEVING NATIVE FORMAT HERE
- itsPrintInfo->WriteTo(itsFileStream);
-
- fi.Success();
- }
- else
- {
- itsFileStream = (TFileStream *)FreeIfObject(itsFileStream);
- fi.ReSignal();
- }
-
- itsFileStream = (TFileStream *)FreeIfObject(itsFileStream);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler::RestorePrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- TPrintInfo* TStdPrintHandler::RestorePrintInfo(TFile* itsFile, Boolean useRsrcFork)
- {
- TPrintInfo * returnVal = NULL;
-
- Handle printResource = NULL;
- #if qGXPrinting
- Boolean isGXFormat = FALSE;
- #endif
-
- if (useRsrcFork && itsFile->HasRsrcFork()) // Read the print info resource
- {
- if (itsFile->IsRsrcForkOpen())
- {
- short saveRefNum = itsFile->UseResource();
- if (ResError() == noErr)
- {
- short idx;
- #if qGXPrinting
- if (gUsingGXPrinting)
- idx = kFirstGXFormatIndex; // Try a GX Format record first
- else
- #endif
- idx = kFirstMacPrintFormatIndex;
-
- for (; idx >=0; --idx)
- {
- short numResources = Count1Resources(kPrintResType[idx]);
-
- if (numResources) // Any at all?
- {
- // Try preferred ID first
- printResource = Get1Resource(kPrintResType[idx], kPrintResNumber[idx]);
-
- // Try any ID next
- if (!printResource)
- printResource = Get1IndResource(kPrintResType[idx], 1);
-
- if (printResource)
- break;
- }
- }
- #if qGXPrinting
- if (idx > kFirstMacPrintFormatIndex)
- isGXFormat = TRUE;
- #endif
- }
- MAUseResFile(saveRefNum);
- }
- if (printResource)
- {
- MAVolatileInit(THandleStream*, aHandleStream, new THandleStream);
- aHandleStream->IHandleStream(printResource, 0);
-
- FailInfo fi;
- Try(fi)
- {
- //•••••••
- TPrintInfo* aPrintInfo = NewTPrintInfo();
-
- #if qGXPrinting
- // NOT native format (THPrint for MacPrint, gxJob for GX)
- if (gUsingGXPrinting && !isGXFormat)
- ((TGXJob*)aPrintInfo)->ConvertFrom(aHandleStream);
- else
- #endif
- aPrintInfo->ReadFrom(aHandleStream);
-
- returnVal = aPrintInfo;
-
- fi.Success();
- }
- else // Recover
- {
- aHandleStream->SetPosition(aHandleStream->GetSize()); // prevent truncation
- aHandleStream = (THandleStream *)FreeIfObject(aHandleStream);
- ReleaseResource(printResource);
- fi.ReSignal();
- }
-
- aHandleStream->SetPosition(aHandleStream->GetSize()); // prevent truncation
- aHandleStream = (THandleStream *)FreeIfObject(aHandleStream);
- ReleaseResource(printResource);
- }
- }
- else
- {
- // This should be changed to have the count in the file before the data.
- // And to identify the type of print record
- MAVolatileInit(TFileStream*, itsFileStream, new TFileStream);
- itsFileStream->IFileStream(itsFile);
-
- FailInfo fi;
- Try(fi)
- {
- //••••••• ASSUME WE'RE STORING/RETRIEVING NATIVE FORMAT HERE
- TPrintInfo* aPrintInfo = NewTPrintInfo();
- aPrintInfo->ReadFrom(itsFileStream);
- returnVal = aPrintInfo;
-
- fi.Success();
- }
- else
- {
- itsFileStream = (TFileStream *)FreeIfObject(itsFileStream);
- fi.ReSignal();
- }
-
- itsFileStream = (TFileStream *)FreeIfObject(itsFileStream);
- }
-
- return returnVal;
- }
-
- //========================================================================================
- // CLASS TPrintCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment PrintSelCommand
- MA_DEFINE_CLASS_M1(TPrintCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintSelCommand
-
- TPrintCommand::TPrintCommand() :
- fStdPrintHandler(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TPrintCommand::~TPrintCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand::IPrintCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintSelCommand
-
- void TPrintCommand::IPrintCommand(CommandNumber itsCommandNumber,
- TStdPrintHandler* itsStdPrintHandler)
- {
- TCommandHandler * theContext = NULL;
-
- if (itsStdPrintHandler->fDocument)
- theContext = itsStdPrintHandler->fDocument;
- else if (itsStdPrintHandler->fView)
- {
- TWindow * itsWindow = itsStdPrintHandler->fView->GetWindow();
- theContext = itsWindow != NULL ? itsWindow : itsStdPrintHandler->fView;
- }
-
- ICommand(itsCommandNumber, theContext, kCantUndo, kDoesNotCauseChange, theContext);
- fStdPrintHandler = itsStdPrintHandler;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- TAppleEvent* TPrintCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, mayFailEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kCoreEventClass, kAEPrint, gServerAddress, kAEWaitReply);
- mayFailEvent = theEvent;
-
- // Send an AppleEvent for recording
- {
- CTempDesc theTargetDesc;
- if (fStdPrintHandler->fDocument)
- {
- TDocument * theDocument = fStdPrintHandler->fDocument;
- theDocument->MakeObjectSpecifier(theTargetDesc, theDocument->GetSpecifierForm());
- }
- else
- {
- FailNonObject(fStdPrintHandler->fView);
- TWindow * theWindow = fStdPrintHandler->fView->GetWindow();
- FailNonObject(theWindow);
- theWindow->MakeObjectSpecifier(theTargetDesc, theWindow->GetSpecifierForm());
- }
-
- theEvent->WriteParameter(keyDirectObject, theTargetDesc);
- }
- fi.Success();
- }
- else // Recover
- {
- mayFailEvent = (TAppleEvent *)FreeIfObject(mayFailEvent);
- fi.ReSignal();
- }
-
- return mayFailEvent;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintCommand::DoIt()
- {
- Boolean setupSuccess = FALSE;
-
- switch (fIdentifier)
- {
- case cPrint:
- setupSuccess = fStdPrintHandler->PoseJobDialog();
- break;
-
- case cPrintOne:
- case cDragPrint:
- setupSuccess = fStdPrintHandler->SetupPrintOne(fIdentifier);
- break;
- }
-
- if (setupSuccess)
- fStdPrintHandler->Print(fIdentifier);
- }
-
- //========================================================================================
- // CLASS TPrintStyleChangeCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TPrintStyleChangeCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- TPrintStyleChangeCommand::TPrintStyleChangeCommand() :
- fNewPrintInfo(NULL),
- fOldPrintInfo(NULL),
- fStdPrintHandler(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::IPrintStyleChangeCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- void TPrintStyleChangeCommand::IPrintStyleChangeCommand(TStdPrintHandler* itsPrintHandler,
- Boolean isUndoable)
- {
- TDocument * changedDocument = itsPrintHandler->fDocument;
- TView * itsView = itsPrintHandler->fView;
- TCommandHandler * itsContext = itsView ? itsView->GetContext(cChangePrinterStyle) : changedDocument->GetContext(cChangePrinterStyle);
-
- ICommand(cChangePrinterStyle, itsContext, isUndoable, kCausesChange, changedDocument);
- fStdPrintHandler = itsPrintHandler;
- fCausesChange = (changedDocument && (changedDocument->fSavePrintInfo));
-
- FailInfo fi;
- Try(fi)
- {
- if (isUndoable)
- {
- fOldPrintInfo = NewTPrintInfo();
- // Make a copy of the old version of the PrintInfo record
- fOldPrintInfo->SetFrom(itsPrintHandler->fPrintInfo);
- }
-
- fNewPrintInfo = NewTPrintInfo();
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- TPrintStyleChangeCommand::~TPrintStyleChangeCommand()
- {
- fOldPrintInfo = (TPrintInfo *)FreeIfObject(fOldPrintInfo);
- fNewPrintInfo = (TPrintInfo *)FreeIfObject(fNewPrintInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- void TPrintStyleChangeCommand::DoIt() // override
- {
- fStdPrintHandler->fPrintInfo->SetFrom(fNewPrintInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- void TPrintStyleChangeCommand::UndoIt() // override
- {
- fStdPrintHandler->fPrintInfo->SetFrom(fOldPrintInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::SetupDependencies:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- void TPrintStyleChangeCommand::SetupDependencies()
- {
- Inherited::SetupDependencies();
-
- if (fStdPrintHandler && fStdPrintHandler->fView && CanBeUndone())
- {
- fStdPrintHandler->fView->AddDependent(this);
- fStdPrintHandler->fPrintInfo->AddDependent(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintDoCommand
-
- void TPrintStyleChangeCommand::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)// Override
- {
- if ((theChange == mClosed) && (changedObject == fStdPrintHandler->fView))
- fContext->CommitLastCommand();
- else if ((theChange == mPrinterChanged) && (changedObject == fStdPrintHandler->fPrintInfo))
- fCanUndo = FALSE;
- else
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- }
-
- //----------------------------------------------------------------------------------------
- // End of UPrinting.cp
-
- #pragma segment Inline
-